|
@@ -4,16 +4,34 @@
|
|
|
class GridEditorUtil {
|
|
class GridEditorUtil {
|
|
|
|
|
|
|
|
constructor() {
|
|
constructor() {
|
|
|
|
|
+ // TODO url
|
|
|
|
|
+ this.lineBeginPartOfGridRE = /(<[^/].*>)/;
|
|
|
|
|
+ this.lineEndPartOfGridRE = /(<\/.*>)/;
|
|
|
|
|
+ this.linePartOfGridRE = /(<.*>)[\s\S]*<\/.*>$/;
|
|
|
this.replaceGridWithHtmlWithEditor = this.replaceGridWithHtmlWithEditor.bind(this);
|
|
this.replaceGridWithHtmlWithEditor = this.replaceGridWithHtmlWithEditor.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- replaceGridWithHtmlWithEditor(editor) {
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * return the postion of the BOD(beginning of grid)
|
|
|
|
|
+ */
|
|
|
|
|
+ getBog(editor) {
|
|
|
const curPos = editor.getCursor();
|
|
const curPos = editor.getCursor();
|
|
|
- editor.getDoc().replaceRange(
|
|
|
|
|
- // dummy data
|
|
|
|
|
- '<div class="container"><div class="row"><div class="col-sm-6 col-md-5 col-lg-12">dummy</div></div></div>',
|
|
|
|
|
- { line: editor.getDoc().getCursor().line, ch: editor.getDoc().getCursor().ch },
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const firstLine = editor.getDoc().firstLine();
|
|
|
|
|
+ return { line: firstLine, ch: curPos.ch };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * return the postion of the EOD(end of grid)
|
|
|
|
|
+ */
|
|
|
|
|
+ getEog(editor) {
|
|
|
|
|
+ const curPos = editor.getCursor();
|
|
|
|
|
+ const lastLine = editor.getDoc().lastLine();
|
|
|
|
|
+ return { line: lastLine, ch: curPos.ch };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ replaceGridWithHtmlWithEditor(editor, grid) {
|
|
|
|
|
+ const curPos = editor.getCursor();
|
|
|
|
|
+ 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);
|
|
|
}
|
|
}
|
|
|
|
|
|