diff --git a/src/components/kri-editor/KriEditorWysiwyg.tsx b/src/components/kri-editor/KriEditorWysiwyg.tsx index 4149555..40c3d90 100644 --- a/src/components/kri-editor/KriEditorWysiwyg.tsx +++ b/src/components/kri-editor/KriEditorWysiwyg.tsx @@ -103,7 +103,6 @@ export function KriEditorWysiwyg(props: KriEditorProps) { const htmlTi = useTextareaInsert(htmlTextareaRef); const [view, setView] = useState("wysiwyg"); - const [wysiwygKey, setWysiwygKey] = useState(0); const [previewSource, setPreviewSource] = useState(value ?? ""); const viewRef = useRef("wysiwyg"); @@ -252,7 +251,7 @@ export function KriEditorWysiwyg(props: KriEditorProps) { }, }, }, - },[wysiwygKey]); + }, []); const restoreSelection = useCallback(() => { if (!editor) return; @@ -482,21 +481,20 @@ export function KriEditorWysiwyg(props: KriEditorProps) { const current = editor.getHTML(); if (normalizedValue !== current && normalizedValue !== optimisticHtmlRef.current) { - // 이미지가 포함된 HTML 업데이트면, 아예 editor를 새로 생성 + // 외부에서 본문이 변경된 경우에만 기존 editor 문서를 갱신한다. editor.commands.setContent(normalizedValue, { emitUpdate: false, parseOptions: {preserveWhitespace: "full"}, }); + + // resize가 활성화된 TipTap 이미지 NodeView는 노드의 src 변경을 기존 DOM에 반영하지 않는다. + // editor 전체 대신 NodeView만 다시 생성해 이미지를 갱신하고 편집 포커스는 유지한다. + if (normalizedValue.includes(" { - if (value.includes(" k + 1); - return; - } - }, [value]); - useEffect(() => { if (!editor) return;