refactor: move deleteTableWhenAllCellsSelected to its own file

This commit is contained in:
Philipp Kühn
2021-04-20 22:58:59 +02:00
parent e0c2460a96
commit 9ca865a253

View File

@@ -4,7 +4,6 @@ import {
ParentConfig, ParentConfig,
mergeAttributes, mergeAttributes,
getExtensionField, getExtensionField,
findParentNodeClosestToPos,
callOrReturn, callOrReturn,
} from '@tiptap/core' } from '@tiptap/core'
import { import {
@@ -29,7 +28,7 @@ import {
import { NodeView } from 'prosemirror-view' import { NodeView } from 'prosemirror-view'
import { TextSelection } from 'prosemirror-state' import { TextSelection } from 'prosemirror-state'
import { createTable } from './utilities/createTable' import { createTable } from './utilities/createTable'
import { isCellSelection } from './utilities/isCellSelection' import { deleteTableWhenAllCellsSelected } from './utilities/deleteTableWhenAllCellsSelected'
import { TableView } from './TableView' import { TableView } from './TableView'
export interface TableOptions { export interface TableOptions {
@@ -190,39 +189,6 @@ export const Table = Node.create<TableOptions>({
}, },
addKeyboardShortcuts() { addKeyboardShortcuts() {
const deleteTableWhenAllCellsSelected = () => {
const { selection } = this.editor.state
if (!isCellSelection(selection)) {
return false
}
let cellCount = 0
const table = findParentNodeClosestToPos(selection.ranges[0].$from, node => {
return node.type.name === 'table'
})
table?.node.descendants(node => {
if (node.type.name === 'table') {
return false
}
if (['tableCell', 'tableHeader'].includes(node.type.name)) {
cellCount += 1
}
})
const allCellsSelected = cellCount === selection.ranges.length
if (!allCellsSelected) {
return false
}
this.editor.commands.deleteTable()
return true
}
return { return {
Tab: () => { Tab: () => {
if (this.editor.commands.goToNextCell()) { if (this.editor.commands.goToNextCell()) {