Ver Fonte

ensure not to reset cursor when save with shortcut key

Yuki Takei há 7 anos atrás
pai
commit
e575679756

+ 12 - 3
resource/js/app.js

@@ -155,6 +155,8 @@ Object.keys(componentMappings).forEach((key) => {
  * @param {object} page Page instance
  * @param {object} page Page instance
  */
  */
 const saveWithShortcutSuccessHandler = function(page) {
 const saveWithShortcutSuccessHandler = function(page) {
+  const editorMode = crowi.getCrowiForJquery().getCurrentEditorMode();
+
   // show toastr
   // show toastr
   toastr.success(undefined, 'Saved successfully', {
   toastr.success(undefined, 'Saved successfully', {
     closeButton: true,
     closeButton: true,
@@ -178,12 +180,15 @@ const saveWithShortcutSuccessHandler = function(page) {
   }
   }
   // re-render PageEditor component
   // re-render PageEditor component
   if (componentInstances.pageEditor != null) {
   if (componentInstances.pageEditor != null) {
-    componentInstances.pageEditor.setMarkdown(page.revision.body);
+    const updateEditorValue = (editorMode !== 'builtin');
+    componentInstances.pageEditor.setMarkdown(page.revision.body, updateEditorValue);
   }
   }
   // set revision id to PageEditorByHackmd
   // set revision id to PageEditorByHackmd
   if (componentInstances.pageEditorByHackmd != null) {
   if (componentInstances.pageEditorByHackmd != null) {
     componentInstances.pageEditorByHackmd.setRevisionId(pageRevisionId);
     componentInstances.pageEditorByHackmd.setRevisionId(pageRevisionId);
-    componentInstances.pageEditorByHackmd.setMarkdown(page.revision.body);
+
+    const updateEditorValue = (editorMode !== 'hackmd');
+    componentInstances.pageEditorByHackmd.setMarkdown(page.revision.body, updateEditorValue);
   }
   }
 };
 };
 
 
@@ -199,6 +204,11 @@ const errorHandler = function(error) {
 };
 };
 
 
 const saveWithShortcut = function(markdown) {
 const saveWithShortcut = function(markdown) {
+  const editorMode = crowi.getCrowiForJquery().getCurrentEditorMode();
+  if (editorMode == null) {
+    // do nothing
+    return;
+  }
   // get options
   // get options
   const options = componentInstances.savePageControls.getCurrentOptionsToSave();
   const options = componentInstances.savePageControls.getCurrentOptionsToSave();
 
 
@@ -226,7 +236,6 @@ const saveWithSubmitButton = function() {
     // do nothing
     // do nothing
     return;
     return;
   }
   }
-
   // get options
   // get options
   const options = componentInstances.savePageControls.getCurrentOptionsToSave();
   const options = componentInstances.savePageControls.getCurrentOptionsToSave();
 
 

+ 6 - 4
resource/js/components/PageEditor.js

@@ -52,7 +52,7 @@ export default class PageEditor extends React.Component {
     this.scrollPreviewByEditorLineWithThrottle = throttle(20, this.scrollPreviewByEditorLine);
     this.scrollPreviewByEditorLineWithThrottle = throttle(20, this.scrollPreviewByEditorLine);
     this.scrollPreviewByCursorMovingWithThrottle = throttle(20, this.scrollPreviewByCursorMoving);
     this.scrollPreviewByCursorMovingWithThrottle = throttle(20, this.scrollPreviewByCursorMoving);
     this.scrollEditorByPreviewScrollWithThrottle = throttle(20, this.scrollEditorByPreviewScroll);
     this.scrollEditorByPreviewScrollWithThrottle = throttle(20, this.scrollEditorByPreviewScroll);
-    this.renderWithDebounce = debounce(50, throttle(100, this.renderPreview));
+    this.renderPreviewWithDebounce = debounce(50, throttle(100, this.renderPreview));
     this.saveDraftWithDebounce = debounce(800, this.saveDraft);
     this.saveDraftWithDebounce = debounce(800, this.saveDraft);
   }
   }
 
 
@@ -65,9 +65,11 @@ export default class PageEditor extends React.Component {
     return this.state.markdown;
     return this.state.markdown;
   }
   }
 
 
-  setMarkdown(markdown) {
+  setMarkdown(markdown, updateEditorValue = true) {
     this.setState({ markdown });
     this.setState({ markdown });
-    this.refs.editor.setValue(markdown);
+    if (updateEditorValue) {
+      this.refs.editor.setValue(markdown);
+    }
   }
   }
 
 
   focusToEditor() {
   focusToEditor() {
@@ -104,7 +106,7 @@ export default class PageEditor extends React.Component {
    * @param {string} value
    * @param {string} value
    */
    */
   onMarkdownChanged(value) {
   onMarkdownChanged(value) {
-    this.renderWithDebounce(value);
+    this.renderPreviewWithDebounce(value);
     this.saveDraftWithDebounce();
     this.saveDraftWithDebounce();
   }
   }
 
 

+ 2 - 2
resource/js/components/PageEditorByHackmd.jsx

@@ -49,9 +49,9 @@ export default class PageEditorByHackmd extends React.PureComponent {
       });
       });
   }
   }
 
 
-  setMarkdown(markdown) {
+  setMarkdown(markdown, updateEditorValue = true) {
     this.setState({ markdown });
     this.setState({ markdown });
-    if (this.state.isInitialized) {
+    if (this.state.isInitialized && updateEditorValue) {
       this.refs.hackmdEditor.setValue(markdown);
       this.refs.hackmdEditor.setValue(markdown);
     }
     }
   }
   }