feat: Shortcut to delete empty table while cells are selected#2052
feat: Shortcut to delete empty table while cells are selected#2052matthewlipski merged 4 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-ai
@blocknote/xl-docx-exporter
@blocknote/xl-email-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
| // Need to use ProseMirror API to check if selection spans table. | ||
| const anchorCellColIndex = | ||
| editor.prosemirrorState.selection.$anchorCell.index(); | ||
| const anchorCellRowIndex = | ||
| editor.prosemirrorState.selection.$anchorCell.index(-1); | ||
| const headCellColIndex = | ||
| editor.prosemirrorState.selection.$headCell.index(); | ||
| const headCellRowIndex = | ||
| editor.prosemirrorState.selection.$headCell.index(-1); | ||
|
|
||
| const minColIndex = Math.min(anchorCellColIndex, headCellColIndex); | ||
| const maxColIndex = Math.max(anchorCellColIndex, headCellColIndex); | ||
| const minRowIndex = Math.min(anchorCellRowIndex, headCellRowIndex); | ||
| const maxRowIndex = Math.max(anchorCellRowIndex, headCellRowIndex); | ||
|
|
||
| if ( | ||
| minColIndex !== 0 || | ||
| maxColIndex !== cols - 1 || | ||
| minRowIndex !== 0 || | ||
| maxRowIndex !== rows - 1 | ||
| ) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Did you test this with merged/split cells? I think that it will actually be a bit off since the number of table cells will not be the same as the number of td nodes. I suggest looking at what: getCellSelection does in tableHandlesPlugin, and either use or come up with something similar to that
There was a problem hiding this comment.
I realized this can be done much simpler - the whole table is selected when each cell is selected, meaning we can just check if the number of selected cells is equal to the number of total cells or if it's less.
nperez0111
left a comment
There was a problem hiding this comment.
Yep, this is simple enough!
Closes #2038