Browse Source

WIP: refactor - impl CodeMirrorEditor.replaceBolToCurrentPos

Yuki Takei 7 years ago
parent
commit
98c39d8fdf

+ 9 - 1
resource/js/components/PageEditor/AbstractEditor.js

@@ -41,7 +41,15 @@ export default class AbstractEditor extends React.Component {
   /**
   /**
    * return strings from current position to EOL(end of line)
    * return strings from current position to EOL(end of line)
    */
    */
-  getStrToEol(editor) {
+  getStrToEol() {
+    throw new Error('this method should be impelemented in subclass');
+  }
+
+  /**
+   * replace Beggining Of Line to current position with param 'text'
+   * @param {string} text
+   */
+  replaceBolToCurrentPos(text) {
     throw new Error('this method should be impelemented in subclass');
     throw new Error('this method should be impelemented in subclass');
   }
   }
 
 

+ 9 - 2
resource/js/components/PageEditor/CodeMirrorEditor.js

@@ -196,6 +196,14 @@ export default class CodeMirrorEditor extends AbstractEditor {
     return editor.getDoc().getRange(curPos, this.getEol());
     return editor.getDoc().getRange(curPos, this.getEol());
   }
   }
 
 
+  /**
+   * @inheritDoc
+   */
+  replaceBolToCurrentPos(text) {
+    const editor = this.getCodeMirror();
+    editor.getDoc().replaceRange(text, this.getBol(), editor.getCursor());
+  }
+
   /**
   /**
    * return the postion of the BOL(beginning of line)
    * return the postion of the BOL(beginning of line)
    */
    */
@@ -333,8 +341,7 @@ export default class CodeMirrorEditor extends AbstractEditor {
 
 
     // text
     // text
     if (types.includes('text/plain')) {
     if (types.includes('text/plain')) {
-      // TODO refactor
-      // pasteHelper.pasteText(editor, event);
+      pasteHelper.pasteText(this, event);
     }
     }
     // files
     // files
     else if (types.includes('Files')) {
     else if (types.includes('Files')) {

+ 1 - 5
resource/js/components/PageEditor/MarkdownListUtil.js

@@ -1,5 +1,3 @@
-import * as codemirror from 'codemirror';
-
 /**
 /**
  * Utility for markdown list
  * Utility for markdown list
  */
  */
@@ -32,9 +30,7 @@ class MarkdownListUtil {
       // replace
       // replace
       if (adjusted != null) {
       if (adjusted != null) {
         event.preventDefault();
         event.preventDefault();
-        // TODO refactor
-        // editor.getDoc().replaceRange(adjusted, this.getBol(editor), editor.getCursor());
-        console.log('replaceRange with:', adjusted);
+        editor.replaceBolToCurrentPos(adjusted);
       }
       }
     }
     }
   }
   }