ryohek %!s(int64=5) %!d(string=hai) anos
pai
achega
e21c3eb349

+ 3 - 1
src/client/js/components/PageEditor/GridEditModal.jsx

@@ -34,7 +34,9 @@ export default class GridEditModal extends React.PureComponent {
 
   pasteCodedGrid() {
     // dummy data
-    const pastedGridData = '<div class="container"><div class="row"><div class="col-sm-6 col-md-5 col-lg-12">dummy</div></div></div>';
+    const pastedGridData = `::: editable-row\n<div class="container">\n  <div class="row">
+    <div class="col-sm-6 col-md-5 col-lg-12">dummy</div>\n  </div>\n</div>\n:::`;
+
     if (this.props.onSave != null) {
       this.props.onSave(pastedGridData);
     }

+ 14 - 12
src/client/js/components/PageEditor/GridEditorUtil.js

@@ -4,10 +4,9 @@
 class GridEditorUtil {
 
   constructor() {
-    // TODO url
-    this.lineBeginPartOfGridRE = /(<[^/].*>)/;
-    this.lineEndPartOfGridRE = /(<\/.*>)/;
-    this.linePartOfGridRE = /(<[^/].*>)[\s\S]*<\/.*>$/;
+    // https://regex101.com/r/7BN2fR/11
+    this.lineBeginPartOfGridRE = /^:::(\s.*)editable-row$/;
+    this.lineEndPartOfGridRE = /^:::$/;
     this.replaceGridWithHtmlWithEditor = this.replaceGridWithHtmlWithEditor.bind(this);
   }
 
@@ -18,6 +17,10 @@ class GridEditorUtil {
     const curPos = editor.getCursor();
     const firstLine = editor.getDoc().firstLine();
 
+    if (this.lineBeginPartOfGridRE.test(editor.getDoc().getLine(curPos.line))) {
+      return { line: curPos.line, ch: 0 };
+    }
+
     let line = curPos.line - 1;
     let isFound = false;
     for (; line >= firstLine; line--) {
@@ -27,7 +30,7 @@ class GridEditorUtil {
         break;
       }
 
-      if (this.lineBeginPartOfGridRE.test(strLine)) {
+      if (this.lineEndPartOfGridRE.test(strLine)) {
         isFound = false;
         break;
       }
@@ -48,7 +51,11 @@ class GridEditorUtil {
     const curPos = editor.getCursor();
     const lastLine = editor.getDoc().lastLine();
 
-    let line = curPos.line;
+    if (this.lineEndPartOfGridRE.test(editor.getDoc().getLine(curPos.line))) {
+      return { line: curPos.line, ch: editor.getDoc().getLine(curPos.line).length };
+    }
+
+    let line = curPos.line + 1;
     let isFound = false;
     for (; line <= lastLine; line++) {
       const strLine = editor.getDoc().getLine(line);
@@ -57,7 +64,7 @@ class GridEditorUtil {
         break;
       }
 
-      if (this.lineEndPartOfGridRE.test(strLine)) {
+      if (this.lineBeginPartOfGridRE.test(strLine)) {
         isFound = false;
         break;
       }
@@ -70,15 +77,10 @@ class GridEditorUtil {
     const eodLine = Math.min(line, lastLine);
     const lineLength = editor.getDoc().getLine(eodLine).length;
     return { line: eodLine, ch: lineLength };
-    // return { line: lastLine, ch: curPos.ch };
   }
 
   replaceGridWithHtmlWithEditor(editor, grid) {
     const curPos = editor.getCursor();
-    console.log('getBog');
-    console.log(this.getBog(editor));
-    console.log('getEog');
-    console.log(this.getEog(editor));
     editor.getDoc().replaceRange(grid.toString(), this.getBog(editor), this.getEog(editor));
     editor.getDoc().setCursor(curPos.line + 1, 2);
   }