Procházet zdrojové kódy

update getMarkdownTable to return null if cursor is not in table

utsushiiro před 7 roky
rodič
revize
02d04795c6

+ 6 - 0
src/client/js/components/PageEditor/MarkdownTableUtil.js

@@ -85,8 +85,14 @@ class MarkdownTableUtil {
 
   /**
    * return MarkdownTable instance of the table where cursor exists
+   * (if cursor is not in the table, return null)
    */
   getMarkdownTable(editor) {
+    const curPos = editor.getCursor();
+    if (!this.linePartOfTableRE.test(editor.getDoc().getLine(curPos.line))) {
+      return null;
+    }
+
     const strFromBotToEot = editor.getDoc().getRange(this.getBot(editor), this.getEot(editor));
     return MarkdownTable.fromMarkdownString(strFromBotToEot);
   }