UBERF-7587 Add table hotkeys (#6066)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-07-13 22:19:39 +07:00 committed by GitHub
parent 6b50e2c6fd
commit ce8683e8e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,12 +13,36 @@
// limitations under the License.
//
import { type Editor } from '@tiptap/core'
import TiptapTable from '@tiptap/extension-table'
import TableNodeView from './TableNodeView.svelte'
import { CellSelection } from '@tiptap/pm/tables'
import { SvelteNodeViewRenderer } from '../../node-view'
import TableNodeView from './TableNodeView.svelte'
import { isTableSelected } from './utils'
export const Table = TiptapTable.extend({
addKeyboardShortcuts () {
return {
'Mod-Backspace': () => handleDelete(this.editor),
'Mod-Delete': () => handleDelete(this.editor)
}
},
addNodeView () {
return SvelteNodeViewRenderer(TableNodeView, {})
}
})
function handleDelete (editor: Editor): boolean {
const { selection } = editor.state
if (selection instanceof CellSelection) {
if (isTableSelected(selection)) {
return editor.commands.deleteTable()
} else if (selection.isColSelection()) {
return editor.commands.deleteColumn()
} else if (selection.isRowSelection()) {
return editor.commands.deleteRow()
}
}
return false
}