From bcf441ea8a0f8893e29e836fc9d1ae589fb5fe0f Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 22 Jan 2021 23:00:43 +0100 Subject: [PATCH] add cell navigation and keyboard shortcuts --- packages/extension-table/src/table.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/extension-table/src/table.ts b/packages/extension-table/src/table.ts index c17cf58a..a9c9dfa7 100644 --- a/packages/extension-table/src/table.ts +++ b/packages/extension-table/src/table.ts @@ -3,7 +3,7 @@ import { Command, Node, mergeAttributes } from '@tiptap/core' import { tableEditing, columnResizing, - // goToNextCell, + goToNextCell, addColumnBefore, addColumnAfter, deleteColumn, @@ -129,6 +129,29 @@ export const Table = Node.create({ // console.log('setCellAttr') // return setCellAttr(name, value) // }, + goToNextCell: (): Command => ({ state, dispatch }) => { + return goToNextCell(1)(state, dispatch) + }, + goToPreviousCell: (): Command => ({ state, dispatch }) => { + return goToNextCell(-1)(state, dispatch) + }, + } + }, + + addKeyboardShortcuts() { + return { + Tab: () => { + if (this.editor.commands.goToNextCell()) { + return true + } + + if (this.editor.commands.addRowAfter()) { + return this.editor.commands.goToNextCell() + } + + return false + }, + 'Shift-Tab': () => this.editor.commands.goToPreviousCell(), } },