From e8045424b2aa3df7b2d3f1a834e5d2bec7375157 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 20 Mar 2026 17:51:23 +0200 Subject: [PATCH] feat(lexical): basic read --- .../src/widgets/type_widgets/text/lexical/index.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/client/src/widgets/type_widgets/text/lexical/index.tsx b/apps/client/src/widgets/type_widgets/text/lexical/index.tsx index db67195faa..80b9e07d1f 100644 --- a/apps/client/src/widgets/type_widgets/text/lexical/index.tsx +++ b/apps/client/src/widgets/type_widgets/text/lexical/index.tsx @@ -55,11 +55,21 @@ function CustomEditorPersistencePlugin({ note, noteContext }: TypeWidgetProps) { noteType: "text", getData() { return { - content: JSON.stringify(editor.toJSON()) + content: JSON.stringify(editor.toJSON().editorState) }; }, onContentChange(newContent) { + if (!newContent) return; + try { + const editorState = editor.parseEditorState(newContent); + editor.setEditorState(editorState); + editor.getEditorState().read(() => { + // Clear history after loading to prevent undoing to empty state + }); + } catch (err) { + console.error("Error parsing Lexical content", err); + } }, });