Просмотр исходного кода

refs 116131: fix editor not resetting when same markdown

Futa Arai 2 лет назад
Родитель
Сommit
e2da74fadd

+ 8 - 0
apps/app/src/components/PageEditor.tsx

@@ -517,6 +517,14 @@ const PageEditor = React.memo((): JSX.Element => {
     }
   }, [initialValue, isIndentSizeForced, mutateCurrentIndentSize]);
 
+  // when transitioning to a different page, if the initialValue is the same,
+  // UnControlled CodeMirror value does not reset, so explicitly set the value to initialValue
+  useEffect(() => {
+    if (currentPagePath != null) {
+      editorRef.current?.setValue(initialValue);
+    }
+  }, [currentPagePath, initialValue]);
+
   if (!isEditable) {
     return <></>;
   }

+ 1 - 1
apps/app/src/components/PageEditor/CodeMirrorEditor.jsx

@@ -571,7 +571,7 @@ class CodeMirrorEditor extends AbstractEditor {
 
   changeHandler(editor, data, value) {
     if (this.props.onChange != null) {
-      const isClean = data.origin == null || editor.isClean();
+      const isClean = data.origin == null || editor.isClean() || value === this.props.value;
       this.props.onChange(value, isClean);
     }