Przeglądaj źródła

Merge pull request #3661 from weseek/fix/5753-5754-check-editor-mode

Fix/5753 5754 check update editor markdown value
Yuki Takei 5 lat temu
rodzic
commit
0d2f246db1
2 zmienionych plików z 13 dodań i 3 usunięć
  1. 1 1
      CHANGES.md
  2. 12 2
      src/client/js/components/PageEditor.jsx

+ 1 - 1
CHANGES.md

@@ -2,7 +2,7 @@
 
 
 ## v4.2.17-RC
 ## v4.2.17-RC
 
 
-*
+* Fix: No unsaved alert is displayed without difference the latest markdown and editor value
 
 
 ## v4.2.16-RC
 ## v4.2.16-RC
 
 

+ 12 - 2
src/client/js/components/PageEditor.jsx

@@ -101,13 +101,23 @@ class PageEditor extends React.Component {
    * @param {string} value
    * @param {string} value
    */
    */
   onMarkdownChanged(value) {
   onMarkdownChanged(value) {
-    const { pageContainer, editorContainer } = this.props;
+    const { pageContainer } = this.props;
     this.setMarkdownStateWithDebounce(value);
     this.setMarkdownStateWithDebounce(value);
     // only when the first time to edit
     // only when the first time to edit
     if (!pageContainer.state.revisionId) {
     if (!pageContainer.state.revisionId) {
       this.saveDraftWithDebounce();
       this.saveDraftWithDebounce();
     }
     }
-    editorContainer.enableUnsavedWarning();
+  }
+
+  // Displays an alert if there is a difference with pageContainer's markdown
+  componentDidUpdate(prevProps, prevState) {
+    const { pageContainer, editorContainer } = this.props;
+
+    if (this.state.markdown !== prevState.markdown) {
+      if (pageContainer.state.markdown !== this.state.markdown) {
+        editorContainer.enableUnsavedWarning();
+      }
+    }
   }
   }
 
 
   /**
   /**