fix: multi-line formatted correctly for sms (#21779)

* fix: multi-line formatted correctly for sms

* fix: tests iteration2
This commit is contained in:
Chai
2025-06-12 14:26:34 +00:00
committed by GitHub
parent cf83038a7a
commit 5e2f06cdea
2 changed files with 6 additions and 3 deletions
@@ -7,7 +7,7 @@ import type { TextEditorProps } from "./types";
describe("Editor", () => {
const defaultProps: TextEditorProps = {
getText: vi.fn(),
getText: vi.fn(() => ""),
setText: vi.fn(),
variables: ["name", "email"],
height: "200px",
@@ -220,6 +220,7 @@ function getSelectedNode(selection: RangeSelection) {
}
export default function ToolbarPlugin(props: TextEditorProps) {
const isInitialized = useRef(false);
const [editor] = useLexicalComposerContext();
const toolbarRef = useRef(null);
const [blockType, setBlockType] = useState("paragraph");
@@ -364,11 +365,13 @@ export default function ToolbarPlugin(props: TextEditorProps) {
}, [props.updateTemplate]);
useEffect(() => {
if (props.setFirstRender) {
if (props.setFirstRender && !isInitialized.current) {
isInitialized.current = true;
props.setFirstRender(false);
editor.update(() => {
const parser = new DOMParser();
const dom = parser.parseFromString(props.getText(), "text/html");
const content = props.getText()?.replace(/\n/g, "<br>");
const dom = parser.parseFromString(content, "text/html");
const nodes = $generateNodesFromDOM(editor, dom);