fix: multi-line formatted correctly for sms (#21779)
* fix: multi-line formatted correctly for sms * fix: tests iteration2
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user