Skip to content
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

[lexical][lexical-table] Bug fix: TablePlugin: - check is current selection in target table node #6979

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/lexical-table/src/LexicalTableObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
$createTextNode,
$getEditor,
$getNodeByKey,
$getRoot,
$getSelection,
$isElementNode,
$isParagraphNode,
Expand Down Expand Up @@ -470,8 +469,6 @@ export class TableObserver {
tableNode.selectPrevious();
// Delete entire table
tableNode.remove();
const rootNode = $getRoot();
rootNode.selectStart();
Comment on lines -473 to -474
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, there is no need for these lines, because when deleting a table via Del, the selection is always transferred to the beginning of the editor, no to the previous node.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this indeed fixes post-deletion selection when nested in a different widget like a collapsible/column box.

return;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/lexical-table/src/LexicalTableSelectionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ export function applyTableHandlers(
return false;
}

if (!$isSelectionInTable(selection, tableNode)) {
return false;
}

Comment on lines +459 to +462
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to place the check after the lines above, otherwise the extension of the selection to the entire table is skipped and the table is deleted incorrectly when anchor or focus points outside the table.

if ($isTableSelection(selection)) {
if (event) {
event.preventDefault();
Expand Down
Loading