[lexical-playground] Bug Fix: Allow deleting empty column layouts via backspace #7636
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
etrepum
left a comment
There was a problem hiding this comment.
The big thing missing here is a test that shows that this works, but I think it can be cleaned up a bit more by using collapseAtStart instead of handling backspace specifically
| const firstLayoutItemKey = container.getFirstChild()?.__key; | ||
| if (firstLayoutItemKey !== currentLayoutItem?.__key) { |
There was a problem hiding this comment.
| const firstLayoutItemKey = container.getFirstChild()?.__key; | |
| if (firstLayoutItemKey !== currentLayoutItem?.__key) { | |
| const firstLayoutItemKey = container.getFirstChild()?.getKey(); | |
| if (firstLayoutItemKey !== currentLayoutItem?.getKey()) { |
| editor.registerCommand( | ||
| KEY_BACKSPACE_COMMAND, | ||
| () => $deleteEmptyLayoutOnBackspace(), | ||
| COMMAND_PRIORITY_LOW, | ||
| ), |
There was a problem hiding this comment.
I think this can be more easily implemented by having LayoutItemNode implement collapseAtStart with a similar implementation, e.g.
function $isEmptyLayoutItemNode(node: LexicalNode): boolean {
return $isLayoutItemNode(node) && !node.getFirstDescendant();
}
export class LayoutItemNode extends ElementNode {
// …
collapseAtStart(): boolean {
const parent = this.getParentNodeOrThrow();
if (
this.is(parent.getFirstChild()) &&
parent.getChildren().every($isEmptyLayoutItemNode)
) {
this.parent.replace($createParagraphNode()).select();
return true;
}
return false;
}
}…ing collapseAtStart
|
Hi etrepum, I've pushed the changes to use Just wanted to confirm — when you mentioned "The big thing missing here is a test that shows that this works," were you referring to adding a unit test under something like "/lexical-playground/unit/LayoutItem.test.tsx"? Happy to add that if you'd like. Thanks again for the helpful feedback! |
|
Yes, a unit or e2e test is missing |
… backspace (#7636) Co-authored-by: Ivaylo Pavlov <ivailo90@gmail.com> Co-authored-by: Bob Ippolito <bob@redivi.com>
Description
Previously, column layouts could not be deleted using only the keyboard — even if they were empty.
This PR enables backspace to delete an empty column layout only when:
Closes #7615
Test plan
Before
After
Screencast.from.21-06-25.08.47.44.AM.IST.webm