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

cursor judgment and grid acquisition

ryohek 5 лет назад
Родитель
Сommit
8498e01547

+ 1 - 1
src/client/js/components/PageEditor/CodeMirrorEditor.jsx

@@ -654,7 +654,7 @@ export default class CodeMirrorEditor extends AbstractEditor {
   }
   }
 
 
   showGridEditorHandler() {
   showGridEditorHandler() {
-    this.gridEditModal.current.show();
+    this.gridEditModal.current.show(geu.getGridHtml(this.getCodeMirror()));
   }
   }
 
 
   showHandsonTableHandler() {
   showHandsonTableHandler() {

+ 22 - 4
src/client/js/components/PageEditor/GridEditorUtil.js

@@ -7,19 +7,38 @@ class GridEditorUtil {
     // https://regex101.com/r/7BN2fR/11
     // https://regex101.com/r/7BN2fR/11
     this.lineBeginPartOfGridRE = /^:::(\s.*)editable-row$/;
     this.lineBeginPartOfGridRE = /^:::(\s.*)editable-row$/;
     this.lineEndPartOfGridRE = /^:::$/;
     this.lineEndPartOfGridRE = /^:::$/;
-    this.isInRow = this.isInRow.bind(this);
+    this.isInGridBlock = this.isInGridBlock.bind(this);
     this.replaceGridWithHtmlWithEditor = this.replaceGridWithHtmlWithEditor.bind(this);
     this.replaceGridWithHtmlWithEditor = this.replaceGridWithHtmlWithEditor.bind(this);
   }
   }
 
 
   /**
   /**
-   * return boolean value whether the cursor position is in a row
+   * return boolean value whether the cursor position is in a grid block
    */
    */
-  isInRow(editor) {
+  isInGridBlock(editor) {
     const bog = this.getBog(editor);
     const bog = this.getBog(editor);
     const eog = this.getEog(editor);
     const eog = this.getEog(editor);
     return (JSON.stringify(bog) !== JSON.stringify(eog));
     return (JSON.stringify(bog) !== JSON.stringify(eog));
   }
   }
 
 
+  /**
+   * return grid html where the cursor is
+   */
+  getGridHtml(editor) {
+    const curPos = editor.getCursor();
+
+    if (this.isInGridBlock(editor)) {
+      const bog = this.getBog(editor);
+      const eog = this.getEog(editor);
+      // skip block begin sesion("::: editable-row")
+      bog.line++;
+      // skip block end sesion(":::")
+      eog.line--;
+      eog.ch = editor.getDoc().getLine(eog.line).length;
+      return editor.getDoc().getRange(bog, eog);
+    }
+    return editor.getDoc().getLine(curPos.line);
+  }
+
   /**
   /**
    * return the postion of the BOD(beginning of grid)
    * return the postion of the BOD(beginning of grid)
    */
    */
@@ -93,7 +112,6 @@ class GridEditorUtil {
     const curPos = editor.getCursor();
     const curPos = editor.getCursor();
     editor.getDoc().replaceRange(grid.toString(), this.getBog(editor), this.getEog(editor));
     editor.getDoc().replaceRange(grid.toString(), this.getBog(editor), this.getEog(editor));
     editor.getDoc().setCursor(curPos.line + 1, 2);
     editor.getDoc().setCursor(curPos.line + 1, 2);
-    console.log(this.isInRow(editor));
   }
   }
 
 
 }
 }