feat: add setCellSelection command

This commit is contained in:
Philipp Kühn 2021-04-27 11:41:38 +02:00
parent 811bf693eb
commit eb7e92f10a

View File

@ -24,6 +24,7 @@ import {
toggleHeaderCell,
setCellAttr,
fixTables,
CellSelection,
} from 'prosemirror-tables'
import { NodeView } from 'prosemirror-view'
import { TextSelection } from 'prosemirror-state'
@ -62,6 +63,7 @@ declare module '@tiptap/core' {
goToNextCell: () => Command,
goToPreviousCell: () => Command,
fixTables: () => Command,
setCellSelection: (position: { anchorCell: number, headCell?: number }) => Command,
}
}
@ -182,6 +184,16 @@ export const Table = Node.create<TableOptions>({
fixTables(state)
}
return true
},
setCellSelection: position => ({ tr, dispatch }) => {
if (dispatch) {
const selection = CellSelection.create(tr.doc, position.anchorCell, position.headCell)
// @ts-ignore
tr.setSelection(selection)
}
return true
},
}