Yuki Takei il y a 7 ans
Parent
commit
8bbfdc6b77

+ 25 - 7
resource/js/components/PageEditor/AbstractEditor.js

@@ -5,6 +5,17 @@ export default class AbstractEditor extends React.Component {
 
 
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
+
+    this.forceToFocus = this.forceToFocus.bind(this);
+    this.setCaretLine = this.setCaretLine.bind(this);
+    this.setScrollTopByLine = this.setScrollTopByLine.bind(this);
+
+    this.getStrFromBol = this.getStrFromBol.bind(this);
+    this.getStrToEol = this.getStrToEol.bind(this);
+    this.insertText = this.insertText.bind(this);
+    this.insertLinebreak = this.insertLinebreak.bind(this);
+
+    this.dispatchSave = this.dispatchSave.bind(this);
   }
   }
 
 
   forceToFocus() {
   forceToFocus() {
@@ -24,13 +35,6 @@ export default class AbstractEditor extends React.Component {
   setScrollTopByLine(line) {
   setScrollTopByLine(line) {
   }
   }
 
 
-  /**
-   * insert text
-   * @param {string} text
-   */
-  insertText(text) {
-  }
-
   /**
   /**
    * return strings from BOL(beginning of line) to current position
    * return strings from BOL(beginning of line) to current position
    */
    */
@@ -53,6 +57,20 @@ export default class AbstractEditor extends React.Component {
     throw new Error('this method should be impelemented in subclass');
     throw new Error('this method should be impelemented in subclass');
   }
   }
 
 
+  /**
+   * insert text
+   * @param {string} text
+   */
+  insertText(text) {
+  }
+
+  /**
+   * insert line break to the current position
+   */
+  insertLinebreak() {
+    this.insertText('\n');
+  }
+
   /**
   /**
    * dispatch onSave event
    * dispatch onSave event
    */
    */

+ 8 - 28
resource/js/components/PageEditor/CodeMirrorEditor.js

@@ -52,20 +52,12 @@ export default class CodeMirrorEditor extends AbstractEditor {
 
 
     this.getCodeMirror = this.getCodeMirror.bind(this);
     this.getCodeMirror = this.getCodeMirror.bind(this);
 
 
-    this.forceToFocus = this.forceToFocus.bind(this);
-    this.setCaretLine = this.setCaretLine.bind(this);
-    this.setScrollTopByLine = this.setScrollTopByLine.bind(this);
-
-    this.getStrFromBol = this.getStrFromBol.bind(this);
-    this.getStrToEol = this.getStrToEol.bind(this);
     this.getBol = this.getBol.bind(this);
     this.getBol = this.getBol.bind(this);
     this.getEol = this.getEol.bind(this);
     this.getEol = this.getEol.bind(this);
-    this.insertLinebreak = this.insertLinebreak.bind(this);
 
 
     this.loadTheme = this.loadTheme.bind(this);
     this.loadTheme = this.loadTheme.bind(this);
     this.loadKeymapMode = this.loadKeymapMode.bind(this);
     this.loadKeymapMode = this.loadKeymapMode.bind(this);
     this.setKeymapMode = this.setKeymapMode.bind(this);
     this.setKeymapMode = this.setKeymapMode.bind(this);
-    this.dispatchSave = this.dispatchSave.bind(this);
     this.handleEnterKey = this.handleEnterKey.bind(this);
     this.handleEnterKey = this.handleEnterKey.bind(this);
 
 
     this.scrollCursorIntoViewHandler = this.scrollCursorIntoViewHandler.bind(this);
     this.scrollCursorIntoViewHandler = this.scrollCursorIntoViewHandler.bind(this);
@@ -122,10 +114,6 @@ export default class CodeMirrorEditor extends AbstractEditor {
    * @inheritDoc
    * @inheritDoc
    */
    */
   forceToFocus() {
   forceToFocus() {
-    if (this.props.isMobile) {
-      return;
-    }
-
     const editor = this.getCodeMirror();
     const editor = this.getCodeMirror();
     // use setInterval with reluctance -- 2018.01.11 Yuki Takei
     // use setInterval with reluctance -- 2018.01.11 Yuki Takei
     const intervalId = setInterval(() => {
     const intervalId = setInterval(() => {
@@ -167,14 +155,6 @@ export default class CodeMirrorEditor extends AbstractEditor {
     editor.scrollTo(null, top);
     editor.scrollTo(null, top);
   }
   }
 
 
-  /**
-   * @inheritDoc
-   */
-  insertText(text) {
-    const editor = this.getCodeMirror();
-    editor.getDoc().replaceSelection(text);
-  }
-
   /**
   /**
    * @inheritDoc
    * @inheritDoc
    */
    */
@@ -201,6 +181,14 @@ export default class CodeMirrorEditor extends AbstractEditor {
     editor.getDoc().replaceRange(text, this.getBol(), editor.getCursor());
     editor.getDoc().replaceRange(text, this.getBol(), editor.getCursor());
   }
   }
 
 
+  /**
+   * @inheritDoc
+   */
+  insertText(text) {
+    const editor = this.getCodeMirror();
+    editor.getDoc().replaceSelection(text);
+  }
+
   /**
   /**
    * return the postion of the BOL(beginning of line)
    * return the postion of the BOL(beginning of line)
    */
    */
@@ -220,14 +208,6 @@ export default class CodeMirrorEditor extends AbstractEditor {
     return { line: curPos.line, ch: lineLength };
     return { line: curPos.line, ch: lineLength };
   }
   }
 
 
-  insertLinebreak(strToEol) {
-    const editor = this.getCodeMirror();
-    codemirror.commands.newlineAndIndent(editor);
-
-    // replace the line with strToEol (abort auto indent)
-    editor.getDoc().replaceRange(strToEol, this.getBol(), this.getEol());
-  }
-
   loadCss(source) {
   loadCss(source) {
     return new Promise((resolve) => {
     return new Promise((resolve) => {
       loadCssSync(source);
       loadCssSync(source);

+ 1 - 1
resource/js/components/PageEditor/MarkdownListInterceptor.js

@@ -33,7 +33,7 @@ export default class MarkdownListInterceptor extends BasicInterceptor {
     // get strings from current position to EOL(end of line) before break the line
     // get strings from current position to EOL(end of line) before break the line
     const strToEol = editor.getStrToEol();
     const strToEol = editor.getStrToEol();
     if (mlu.indentAndMarkRE.test(strToEol)) {
     if (mlu.indentAndMarkRE.test(strToEol)) {
-      editor.insertLinebreak(strToEol);
+      editor.insertLinebreak();
 
 
       // report to manager that handling was done
       // report to manager that handling was done
       context.handlers.push(this.className);
       context.handlers.push(this.className);