Repository navigation
[lexical-table] Bug Fix: Add fallback selection to InsertTableCommand - #7316
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
etrepum
left a comment
There was a problem hiding this comment.
Adding a test would be a good idea, since as you said the playground doesn’t do this there’s no confirmation that this fixes anything
|
Unfortunately I could not reproduce this in the headless unit test environment. I can't do an e2e test without changing playground behaviour. I updated the playground so now the insert is async and the button renders as disabled, which is nice when you insert a huge table and it takes a moment. Now the table tests (eg I'll understand if you don't want these playground changes. |
|
Earlier I was missing discreet updates to get the test sequencing correct. I've also added a test for basic table insertion. The other tests checked that nested tables was NOT being inserted, and since the commands weren't registered, no tables could be inserted. |
Description
If you try to insert a table asynchronously when the editor is not focused, the table is not inserted (because there is no selection)
This can happen if you focus an input field (like row count in the playground), and then dispatch INSERT_TABLE_COMMAND async.
Tables are not inserted async in the playground so it's not a problem, but it can easily be reproduced by wrapping the insert command in a setTimeout in packages/lexical-playground/src/plugins/TablePlugin.tsx
This PR adds a fallback to
$getPreviousSelection()in the table insert command handler. Same as #4570Note that that actual insertion uses
$insertNodeToNearestRoot, which already uses the same fallback. This change simply prevents the command from exiting early.