-
-
Notifications
You must be signed in to change notification settings - Fork 621
feat: Shortcut to delete empty table while cells are selected #2052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is simple enough!
Closes #2038