diff options
author | Max <max@nextcloud.com> | 2022-03-16 16:55:39 +0300 |
---|---|---|
committer | Max <max@nextcloud.com> | 2022-03-31 15:29:23 +0300 |
commit | fca037f64786bee5f0b37860d97c159d18efb027 (patch) | |
tree | 6bf84229a383362b4855a65d440de65a553af91a /src | |
parent | 11ccb112ee263c58eed86f7747cb257ade933116 (diff) |
fix: make tab leave table on last cell.
Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nodes/Table.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/nodes/Table.js b/src/nodes/Table.js index 5c064939e..26e0b2069 100644 --- a/src/nodes/Table.js +++ b/src/nodes/Table.js @@ -1,6 +1,7 @@ import { Table } from '@tiptap/extension-table' import { Node, mergeAttributes } from '@tiptap/core' import { TextSelection } from 'prosemirror-state' +import { isInTable } from 'prosemirror-tables' /* * Markdown tables do not include captions. @@ -73,6 +74,19 @@ export default Table.extend({ } return true }, + // move to the next node after the table from the last cell + leaveTable: () => ({ tr, dispatch, editor }) => { + if (!isInTable(tr)) return false + const { $head, empty } = tr.selection + if (!empty) return false + // the selection can temporarily be inside the table but outside of cells. + const tableDepth = $head.depth < 3 ? 1 : $head.depth - 2 + const next = tr.doc.resolve($head.after(tableDepth) + 1) + const selection = TextSelection.near(next) + const transaction = tr.setSelection(selection) + if (dispatch) dispatch(transaction.scrollIntoView()) + return true + }, } }, @@ -85,4 +99,11 @@ export default Table.extend({ state.closeBlock(node) }, + addKeyboardShortcuts() { + return { + ...this.parent(), + Tab: () => this.editor.commands.goToNextCell() || this.editor.commands.leaveTable(), + } + }, + }) |