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

update getMarkdownTable to return null if cursor is not in table

utsushiiro 7 лет назад
Родитель
Сommit
02d04795c6
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      src/client/js/components/PageEditor/MarkdownTableUtil.js

+ 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);
   }