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 | |
parent | 11ccb112ee263c58eed86f7747cb257ade933116 (diff) |
fix: make tab leave table on last cell.
Signed-off-by: Max <max@nextcloud.com>
-rw-r--r-- | package-lock.json | 1 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/nodes/Table.js | 21 |
3 files changed, 23 insertions, 0 deletions
diff --git a/package-lock.json b/package-lock.json index 19413d4dc..3f4450357 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,6 +61,7 @@ "prosemirror-model": "^1.16.1", "prosemirror-schema-list": "^1.1.6", "prosemirror-state": "^1.3.4", + "prosemirror-tables": "^1.1.1", "prosemirror-transform": "^1.4.0", "prosemirror-utils": "^1.0.0-0", "prosemirror-view": "^1.23.10", diff --git a/package.json b/package.json index d77292092..6cd8f24ac 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,7 @@ "prosemirror-model": "^1.16.1", "prosemirror-schema-list": "^1.1.6", "prosemirror-state": "^1.3.4", + "prosemirror-tables": "^1.1.1", "prosemirror-transform": "^1.4.0", "prosemirror-utils": "^1.0.0-0", "prosemirror-view": "^1.23.10", 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(), + } + }, + }) |