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

Merge pull request #7625 from weseek/fix/115285-116132-editor-not-resetting-when-same-markdown

fix: Editor not resetting when the same markdown
Yuki Takei 2 лет назад
Родитель
Сommit
67f8c9e701

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

@@ -517,6 +517,14 @@ const PageEditor = React.memo((): JSX.Element => {
     }
     }
   }, [initialValue, isIndentSizeForced, mutateCurrentIndentSize]);
   }, [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) {
   if (!isEditable) {
     return <></>;
     return <></>;
   }
   }

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

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