Skip to content

Commit

Permalink
fix: editor readonly content set properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Palanikannan1437 committed Sep 13, 2024
1 parent fa5cfd5 commit 78b1c50
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { UploadImageExtensionStorage } from "@/extensions/custom-image";
export const CustomImageComponentWithoutProps = () =>
Image.extend<{}, UploadImageExtensionStorage>({
name: "imageComponent",
group: "inline",
draggable: true,
selectable: true,
group: "block",
atom: true,
draggable: true,

addAttributes() {
return {
Expand All @@ -21,12 +22,6 @@ export const CustomImageComponentWithoutProps = () =>
height: {
default: "auto",
},
["data-type"]: {
default: this.name,
},
["data-file"]: {
default: null,
},
["id"]: {
default: null,
},
Expand All @@ -38,6 +33,9 @@ export const CustomImageComponentWithoutProps = () =>
{
tag: "image-component",
},
{
tag: "img",
},
];
},

Expand All @@ -50,8 +48,6 @@ export const CustomImageComponentWithoutProps = () =>
fileMap: new Map(),
};
},
}).configure({
inline: true,
});

export default CustomImageComponentWithoutProps;
2 changes: 1 addition & 1 deletion packages/editor/src/core/hooks/use-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const useEditor = (props: CustomEditorProps) => {
editorRef.current?.commands.clearContent(emitUpdate);
},
setEditorValue: (content: string) => {
editorRef.current?.commands.setContent(content);
editorRef.current?.commands.setContent(content, false, { preserveWhitespace: "full" });
},
setEditorValueAtCursorPosition: (content: string) => {
if (savedSelection) {
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/core/hooks/use-read-only-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const useReadOnlyEditor = ({
// for syncing swr data on tab refocus etc
useEffect(() => {
if (initialValue === null || initialValue === undefined) return;
if (editor && !editor.isDestroyed) editor?.commands.setContent(initialValue);
if (editor && !editor.isDestroyed) editor?.commands.setContent(initialValue, false, { preserveWhitespace: "full" });
}, [editor, initialValue]);

const editorRef: MutableRefObject<Editor | null> = useRef(null);
Expand All @@ -68,7 +68,7 @@ export const useReadOnlyEditor = ({
editorRef.current?.commands.clearContent();
},
setEditorValue: (content: string) => {
editorRef.current?.commands.setContent(content);
editorRef.current?.commands.setContent(content, false, { preserveWhitespace: "full" });
},
getMarkDown: (): string => {
const markdownOutput = editorRef.current?.storage.markdown.getMarkdown();
Expand Down

0 comments on commit 78b1c50

Please sign in to comment.