Browse Source

Revert "Revert "fix util""

This reverts commit ef1d37731cb1d8c397e3ec31201559dd0855e855.
soumaeda 2 years ago
parent
commit
ed4c87f331
1 changed files with 7 additions and 5 deletions
  1. 7 5
      apps/app/src/components/PageEditor/MarkdownDrawioUtil.js

+ 7 - 5
apps/app/src/components/PageEditor/MarkdownDrawioUtil.js

@@ -69,7 +69,8 @@ class MarkdownDrawioUtil {
       return null;
     }
 
-    const botLine = Math.max(this.firstLineNum(), line);
+    const firstLineNum = this.firstLineNum();
+    const botLine = Math.max(firstLineNum, line);
     return this.getLine(editor, botLine).from;
   }
 
@@ -102,7 +103,8 @@ class MarkdownDrawioUtil {
       return null;
     }
 
-    const eodLine = Math.min(line, this.lastLineNum(editor));
+    const lastLineNum = this.lastLineNum(editor);
+    const eodLine = Math.min(line, lastLineNum);
     return this.getLine(editor, eodLine).to;
   }
 
@@ -149,8 +151,8 @@ class MarkdownDrawioUtil {
       endPos = this.getEod(editor);
     }
     else {
-      beginPos = this.getCursorLine(editor).from;
-      endPos = this.getCursorLine(editor).to;
+      beginPos = this.curPos(editor);
+      endPos = this.curPos(editor);
     }
 
     editor.dispatch({
@@ -195,7 +197,7 @@ class MarkdownDrawioUtil {
     const lineNumbers = [];
     // refs: https://github.com/codemirror/CodeMirror/blob/5.64.0/addon/fold/foldcode.js#L106-L111
     for (let i = this.firstLineNum(), e = this.lastLineNum(editor); i <= e; i++) {
-      const lineText = this.getLine(editor, i + 1).text;
+      const lineText = this.getLine(editor, i).text;
       const match = this.lineBeginPartOfDrawioRE.exec(lineText);
       if (match) {
         lineNumbers.push(i);