Skip to content

Commit

Permalink
feat: add setCellSelection command
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed Apr 27, 2021
1 parent 811bf69 commit eb7e92f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/extension-table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
toggleHeaderCell,
setCellAttr,
fixTables,
CellSelection,
} from 'prosemirror-tables'
import { NodeView } from 'prosemirror-view'
import { TextSelection } from 'prosemirror-state'
Expand Down Expand Up @@ -62,6 +63,7 @@ declare module '@tiptap/core' {
goToNextCell: () => Command,
goToPreviousCell: () => Command,
fixTables: () => Command,
setCellSelection: (position: { anchorCell: number, headCell?: number }) => Command,
}
}

Expand Down Expand Up @@ -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
},
}
Expand Down

0 comments on commit eb7e92f

Please sign in to comment.