kosei-n 2 лет назад
Родитель
Сommit
700770d040

+ 10 - 2
packages/editor/src/services/table-util/insert-new-row-to-table-markdown.ts

@@ -86,10 +86,17 @@ export const mergeMarkdownTable = (mdtableList: MarkdownTable[]): MarkdownTable
 export const replaceFocusedMarkdownTableWithEditor = (
 export const replaceFocusedMarkdownTableWithEditor = (
     editor: EditorView, table: MarkdownTable,
     editor: EditorView, table: MarkdownTable,
 ): void => {
 ): void => {
+  const curPos = getCurPos(editor);
   const botPos = getBot(editor);
   const botPos = getBot(editor);
   const eotPos = getEot(editor);
   const eotPos = getEot(editor);
 
 
-  const nextLine = editor.state.doc.lineAt(getCurPos(editor)).number + 1;
+  const curLine = editor.state.doc.lineAt(curPos).number;
+  const nextLine = curLine + 1;
+
+  const eolPos = editor.state.doc.line(curLine).to;
+  const strToEol = editor.state.sliceDoc(curPos, eolPos);
+
+  const isLastRow = getStrToEot(editor) === strToEol;
 
 
   editor.dispatch({
   editor.dispatch({
     changes: {
     changes: {
@@ -99,7 +106,8 @@ export const replaceFocusedMarkdownTableWithEditor = (
     },
     },
   });
   });
 
 
-  const nextCurPos = editor.state.doc.line(nextLine).from + 2;
+
+  const nextCurPos = isLastRow ? editor.state.doc.line(curLine).from + 2 : editor.state.doc.line(nextLine).from + 2;
 
 
   editor.dispatch({
   editor.dispatch({
     selection: { anchor: nextCurPos },
     selection: { anchor: nextCurPos },

+ 1 - 1
packages/editor/src/services/table-util/markdown-table.js

@@ -1,5 +1,5 @@
 import csvToMarkdown from 'csv-to-markdown-table';
 import csvToMarkdown from 'csv-to-markdown-table';
-import markdownTable from 'markdown-table';
+import { markdownTable } from 'markdown-table';
 import stringWidth from 'string-width';
 import stringWidth from 'string-width';
 
 
 // https://github.com/markdown-it/markdown-it/blob/d29f421927e93e88daf75f22089a3e732e195bd2/lib/rules_block/table.js#L83
 // https://github.com/markdown-it/markdown-it/blob/d29f421927e93e88daf75f22089a3e732e195bd2/lib/rules_block/table.js#L83

+ 5 - 0
yarn.lock

@@ -12008,6 +12008,11 @@ markdown-it@^13.0.1:
     mdurl "^1.0.1"
     mdurl "^1.0.1"
     uc.micro "^1.0.5"
     uc.micro "^1.0.5"
 
 
+markdown-table@3.0.3:
+  version "3.0.3"
+  resolved "https://registry.yarnpkg.com/markdown-table/-/markdown-table-3.0.3.tgz#e6331d30e493127e031dd385488b5bd326e4a6bd"
+  integrity sha512-Z1NL3Tb1M9wH4XESsCDEksWoKTdlUafKc4pt0GRwjUyXaCFZ+dc3g2erqB6zm3szA2IUSi7VnPI+o/9jnxh9hw==
+
 markdown-table@^1.1.1:
 markdown-table@^1.1.1:
   version "1.1.1"
   version "1.1.1"
   resolved "https://registry.yarnpkg.com/markdown-table/-/markdown-table-1.1.1.tgz#4b3dd3a133d1518b8ef0dbc709bf2a1b4824bc8c"
   resolved "https://registry.yarnpkg.com/markdown-table/-/markdown-table-1.1.1.tgz#4b3dd3a133d1518b8ef0dbc709bf2a1b4824bc8c"