From 0fba523a81e5eea3fa40ce3a1381c923a8ba4bd9 Mon Sep 17 00:00:00 2001 From: VipinDevelops Date: Thu, 15 May 2025 14:25:28 +0530 Subject: [PATCH 1/2] fix: handle symbols and space --- packages/editor/src/core/hooks/use-editor.ts | 7 ++++--- packages/editor/src/core/hooks/use-read-only-editor.ts | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/core/hooks/use-editor.ts b/packages/editor/src/core/hooks/use-editor.ts index cf9d04d83e1..ad2f20981b4 100644 --- a/packages/editor/src/core/hooks/use-editor.ts +++ b/packages/editor/src/core/hooks/use-editor.ts @@ -77,11 +77,12 @@ export const useEditor = (props: CustomEditorProps) => { immediatelyRender: false, shouldRerenderOnTransaction: false, autofocus, + parseOptions: { preserveWhitespace: true }, editorProps: { ...CoreEditorProps({ editorClassName, + ...editorProps, }), - ...editorProps, }, extensions: [ ...CoreEditorExtensions({ @@ -113,7 +114,7 @@ export const useEditor = (props: CustomEditorProps) => { if (value == null) return; if (editor && !editor.isDestroyed && !editor.storage.imageComponent?.uploadInProgress) { try { - editor.commands.setContent(value, false, { preserveWhitespace: "full" }); + editor.commands.setContent(value, false, { preserveWhitespace: true }); if (editor.state.selection) { const docLength = editor.state.doc.content.size; const relativePosition = Math.min(editor.state.selection.from, docLength - 1); @@ -146,7 +147,7 @@ export const useEditor = (props: CustomEditorProps) => { editor?.chain().setMeta("skipImageDeletion", true).clearContent(emitUpdate).run(); }, setEditorValue: (content: string, emitUpdate = false) => { - editor?.commands.setContent(content, emitUpdate, { preserveWhitespace: "full" }); + editor?.commands.setContent(content, emitUpdate, { preserveWhitespace: true }); }, setEditorValueAtCursorPosition: (content: string) => { if (editor?.state.selection) { diff --git a/packages/editor/src/core/hooks/use-read-only-editor.ts b/packages/editor/src/core/hooks/use-read-only-editor.ts index b50b56b02dc..d50e84a524c 100644 --- a/packages/editor/src/core/hooks/use-read-only-editor.ts +++ b/packages/editor/src/core/hooks/use-read-only-editor.ts @@ -45,6 +45,7 @@ export const useReadOnlyEditor = (props: CustomReadOnlyEditorProps) => { immediatelyRender: true, shouldRerenderOnTransaction: false, content: typeof initialValue === "string" && initialValue.trim() !== "" ? initialValue : "

", + parseOptions: { preserveWhitespace: true }, editorProps: { ...CoreReadOnlyEditorProps({ editorClassName, @@ -70,7 +71,7 @@ export const useReadOnlyEditor = (props: CustomReadOnlyEditorProps) => { // for syncing swr data on tab refocus etc useEffect(() => { if (initialValue === null || initialValue === undefined) return; - if (editor && !editor.isDestroyed) editor?.commands.setContent(initialValue, false, { preserveWhitespace: "full" }); + if (editor && !editor.isDestroyed) editor?.commands.setContent(initialValue, false, { preserveWhitespace: true }); }, [editor, initialValue]); useImperativeHandle(forwardedRef, () => ({ @@ -78,7 +79,7 @@ export const useReadOnlyEditor = (props: CustomReadOnlyEditorProps) => { editor?.chain().setMeta("skipImageDeletion", true).clearContent(emitUpdate).run(); }, setEditorValue: (content: string, emitUpdate = false) => { - editor?.commands.setContent(content, emitUpdate, { preserveWhitespace: "full" }); + editor?.commands.setContent(content, emitUpdate, { preserveWhitespace: true }); }, getMarkDown: (): string => { const markdownOutput = editor?.storage.markdown.getMarkdown(); From 5f1d23a72639dc00f7d74a5c4744c56036ff0b7b Mon Sep 17 00:00:00 2001 From: VipinDevelops Date: Fri, 30 May 2025 16:33:29 +0530 Subject: [PATCH 2/2] chore: refactor --- packages/editor/src/core/hooks/use-editor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/core/hooks/use-editor.ts b/packages/editor/src/core/hooks/use-editor.ts index c9404676f9b..ce3cdbe5fb5 100644 --- a/packages/editor/src/core/hooks/use-editor.ts +++ b/packages/editor/src/core/hooks/use-editor.ts @@ -85,8 +85,8 @@ export const useEditor = (props: CustomEditorProps) => { editorProps: { ...CoreEditorProps({ editorClassName, - ...editorProps, }), + ...editorProps, }, extensions: [ ...CoreEditorExtensions({