mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-03 08:57:14 +03:00
UBERF-7587 Add table hotkeys (#6066)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
6b50e2c6fd
commit
ce8683e8e0
@ -13,12 +13,36 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import { type Editor } from '@tiptap/core'
|
||||||
import TiptapTable from '@tiptap/extension-table'
|
import TiptapTable from '@tiptap/extension-table'
|
||||||
import TableNodeView from './TableNodeView.svelte'
|
import { CellSelection } from '@tiptap/pm/tables'
|
||||||
import { SvelteNodeViewRenderer } from '../../node-view'
|
import { SvelteNodeViewRenderer } from '../../node-view'
|
||||||
|
import TableNodeView from './TableNodeView.svelte'
|
||||||
|
import { isTableSelected } from './utils'
|
||||||
|
|
||||||
export const Table = TiptapTable.extend({
|
export const Table = TiptapTable.extend({
|
||||||
|
addKeyboardShortcuts () {
|
||||||
|
return {
|
||||||
|
'Mod-Backspace': () => handleDelete(this.editor),
|
||||||
|
'Mod-Delete': () => handleDelete(this.editor)
|
||||||
|
}
|
||||||
|
},
|
||||||
addNodeView () {
|
addNodeView () {
|
||||||
return SvelteNodeViewRenderer(TableNodeView, {})
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user