|
@@ -83,20 +83,28 @@ export const mergeMarkdownTable = (mdtableList: MarkdownTable[]): MarkdownTable
|
|
|
return (new MarkdownTable(newTable, options));
|
|
return (new MarkdownTable(newTable, options));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-export const replaceFocusedMarkdownTableWithEditor = (
|
|
|
|
|
- editor: EditorView, table: MarkdownTable,
|
|
|
|
|
-): void => {
|
|
|
|
|
|
|
+const addRow = (editor: EditorView) => {
|
|
|
|
|
+ const strFromBot = getStrFromBot(editor);
|
|
|
|
|
+
|
|
|
|
|
+ let table = MarkdownTable.fromMarkdownString(strFromBot);
|
|
|
|
|
+
|
|
|
|
|
+ addRowToMarkdownTable(table);
|
|
|
|
|
+
|
|
|
|
|
+ const strToEot = getStrToEot(editor);
|
|
|
|
|
+
|
|
|
|
|
+ const tableBottom = MarkdownTable.fromMarkdownString(strToEot);
|
|
|
|
|
+
|
|
|
|
|
+ if (tableBottom.table.length > 0) {
|
|
|
|
|
+ table = mergeMarkdownTable([table, tableBottom]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const curPos = getCurPos(editor);
|
|
const curPos = getCurPos(editor);
|
|
|
- const botPos = getBot(editor);
|
|
|
|
|
- const eotPos = getEot(editor);
|
|
|
|
|
|
|
|
|
|
const curLine = editor.state.doc.lineAt(curPos).number;
|
|
const curLine = editor.state.doc.lineAt(curPos).number;
|
|
|
const nextLine = curLine + 1;
|
|
const nextLine = curLine + 1;
|
|
|
|
|
|
|
|
- const eolPos = editor.state.doc.line(curLine).to;
|
|
|
|
|
- const strToEol = editor.state.sliceDoc(curPos, eolPos);
|
|
|
|
|
-
|
|
|
|
|
- const isLastRow = getStrToEot(editor) === strToEol;
|
|
|
|
|
|
|
+ const botPos = getBot(editor);
|
|
|
|
|
+ const eotPos = getEot(editor);
|
|
|
|
|
|
|
|
editor.dispatch({
|
|
editor.dispatch({
|
|
|
changes: {
|
|
changes: {
|
|
@@ -106,32 +114,13 @@ export const replaceFocusedMarkdownTableWithEditor = (
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- const nextCurPos = isLastRow ? editor.state.doc.line(curLine).from + 2 : editor.state.doc.line(nextLine).from + 2;
|
|
|
|
|
|
|
+ const nextCurPos = editor.state.doc.line(nextLine).from + 2;
|
|
|
|
|
|
|
|
editor.dispatch({
|
|
editor.dispatch({
|
|
|
selection: { anchor: nextCurPos },
|
|
selection: { anchor: nextCurPos },
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const addRow = (editor: EditorView) => {
|
|
|
|
|
- const strFromBot = getStrFromBot(editor);
|
|
|
|
|
-
|
|
|
|
|
- let table = MarkdownTable.fromMarkdownString(strFromBot);
|
|
|
|
|
-
|
|
|
|
|
- addRowToMarkdownTable(table);
|
|
|
|
|
-
|
|
|
|
|
- const strToEot = getStrToEot(editor);
|
|
|
|
|
-
|
|
|
|
|
- const tableBottom = MarkdownTable.fromMarkdownString(strToEot);
|
|
|
|
|
-
|
|
|
|
|
- if (tableBottom.table.length > 0) {
|
|
|
|
|
- table = mergeMarkdownTable([table, tableBottom]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- replaceFocusedMarkdownTableWithEditor(editor, table);
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
const removeRow = (editor: EditorView) => {
|
|
const removeRow = (editor: EditorView) => {
|
|
|
|
|
|
|
|
const curPos = getCurPos(editor);
|
|
const curPos = getCurPos(editor);
|
|
@@ -158,7 +147,32 @@ const removeRow = (editor: EditorView) => {
|
|
|
const reformTable = (editor: EditorView) => {
|
|
const reformTable = (editor: EditorView) => {
|
|
|
const tableStr = getStrFromBot(editor) + getStrToEot(editor);
|
|
const tableStr = getStrFromBot(editor) + getStrToEot(editor);
|
|
|
const table = MarkdownTable.fromMarkdownString(tableStr);
|
|
const table = MarkdownTable.fromMarkdownString(tableStr);
|
|
|
- replaceFocusedMarkdownTableWithEditor(editor, table);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const curPos = getCurPos(editor);
|
|
|
|
|
+ const botPos = getBot(editor);
|
|
|
|
|
+ const eotPos = getEot(editor);
|
|
|
|
|
+
|
|
|
|
|
+ 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({
|
|
|
|
|
+ changes: {
|
|
|
|
|
+ from: botPos,
|
|
|
|
|
+ to: eotPos,
|
|
|
|
|
+ insert: table.toString(),
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const nextCurPos = isLastRow ? editor.state.doc.line(curLine).to : editor.state.doc.line(nextLine).from + 2;
|
|
|
|
|
+
|
|
|
|
|
+ editor.dispatch({
|
|
|
|
|
+ selection: { anchor: nextCurPos },
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const insertNewRowToMarkdownTable = (editor: EditorView): void => {
|
|
export const insertNewRowToMarkdownTable = (editor: EditorView): void => {
|