|
|
@@ -11,56 +11,6 @@ class MarkdownLinkUtil {
|
|
|
this.isInTable = this.isInTable.bind(this);
|
|
|
}
|
|
|
|
|
|
- getBot(editor) {
|
|
|
- const curPos = editor.getCursor();
|
|
|
- if (!this.isInTable(editor)) {
|
|
|
- return { line: curPos.line, ch: curPos.ch };
|
|
|
- }
|
|
|
-
|
|
|
- const firstLine = editor.getDoc().firstLine();
|
|
|
- let line = curPos.line - 1;
|
|
|
- for (; line >= firstLine; line--) {
|
|
|
- const strLine = editor.getDoc().getLine(line);
|
|
|
- if (!this.linePartOfTableRE.test(strLine)) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- const botLine = Math.max(firstLine, line + 1);
|
|
|
- return { line: botLine, ch: 0 };
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * return the postion of the EOT(end of table)
|
|
|
- * (If the cursor is not in a table, return its position)
|
|
|
- */
|
|
|
- getEot(editor) {
|
|
|
- const curPos = editor.getCursor();
|
|
|
- if (!this.isInTable(editor)) {
|
|
|
- return { line: curPos.line, ch: curPos.ch };
|
|
|
- }
|
|
|
-
|
|
|
- const lastLine = editor.getDoc().lastLine();
|
|
|
- let line = curPos.line + 1;
|
|
|
- for (; line <= lastLine; line++) {
|
|
|
- const strLine = editor.getDoc().getLine(line);
|
|
|
- if (!this.linePartOfTableRE.test(strLine)) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- const eotLine = Math.min(line - 1, lastLine);
|
|
|
- const lineLength = editor.getDoc().getLine(eotLine).length;
|
|
|
- return { line: eotLine, ch: lineLength };
|
|
|
- }
|
|
|
-
|
|
|
- getMarkdownLink(editor) {
|
|
|
- if (!this.isInTable(editor)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- const strFromBotToEot = editor.getDoc().getRange(this.getBot(editor), this.getEot(editor));
|
|
|
- return MarkdownTable.fromMarkdownString(strFromBotToEot);
|
|
|
- }
|
|
|
-
|
|
|
getSelectedTextInEditor(editor) {
|
|
|
return editor.getDoc().getSelection();
|
|
|
}
|