Skip to content

Commit

Permalink
Fix #5543 insertText('') was inserting Text as child of "table node" …
Browse files Browse the repository at this point in the history
…instead of root before tablerow resulting in table node not getting deleted (#5799)
  • Loading branch information
Sahejkm committed Apr 2, 2024
1 parent f2ac531 commit 2b2a4f6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
23 changes: 23 additions & 0 deletions packages/lexical-playground/__tests__/e2e/Selection.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,27 @@ test.describe('Selection', () => {
`,
);
});

test('Can delete table node present at the end #5543', async ({
page,
isPlainText,
isCollab,
}) => {
test.skip(isPlainText);

await focusEditor(page);
await insertTable(page, 1, 2);
await page.keyboard.press('ArrowDown');
await page.keyboard.down('Shift');
await page.keyboard.press('ArrowUp');
await page.keyboard.up('Shift');
await page.keyboard.press('Backspace');
await assertHTML(
page,
html`
<p class="PlaygroundEditorTheme__paragraph"><br /></p>
<p class="PlaygroundEditorTheme__paragraph"><br /></p>
`,
);
});
});
12 changes: 8 additions & 4 deletions packages/lexical-table/src/LexicalTableSelectionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,14 +693,18 @@ export function applyTableHandlers(
const newSelection = selection.clone();
if (isFocusInside) {
newSelection.focus.set(
tableNode.getKey(),
isBackward ? 0 : tableNode.getChildrenSize(),
tableNode.getParentOrThrow().getKey(),
isBackward
? tableNode.getIndexWithinParent()
: tableNode.getIndexWithinParent() + 1,
'element',
);
} else {
newSelection.anchor.set(
tableNode.getKey(),
isBackward ? tableNode.getChildrenSize() : 0,
tableNode.getParentOrThrow().getKey(),
isBackward
? tableNode.getIndexWithinParent() + 1
: tableNode.getIndexWithinParent(),
'element',
);
}
Expand Down

0 comments on commit 2b2a4f6

Please sign in to comment.