Skip to content

Commit

Permalink
Fix failing insertNodes when selection is null (#5956)
Browse files Browse the repository at this point in the history
  • Loading branch information
zurfyx authored Apr 24, 2024
1 parent 387f427 commit 537054f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2681,10 +2681,17 @@ export function $getTextContent(): string {
}

function removeTextAndSplitBlock(selection: RangeSelection): number {
let selection_ = selection;
if (!selection.isCollapsed()) {
selection.removeText();
selection_.removeText();
}
const selection_ = $getSelection();
// A new selection can originate as a result of node replacement, in which case is registered via
// $setSelection
const newSelection = $getSelection();
if ($isRangeSelection(newSelection)) {
selection_ = newSelection;
}

invariant(
$isRangeSelection(selection_),
'Unexpected dirty selection to be null',
Expand Down
5 changes: 4 additions & 1 deletion scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,8 @@
"157": "Expected tableNode to have a parent TableNode",
"158": "Expected gridParent to have a parent",
"159": "Expected focusCellParent to have a parent",
"160": "Expected TableCellNode parent to be a TableRowNode"
"160": "Expected TableCellNode parent to be a TableRowNode",
"161": "Unexpected dirty selection to be null",
"162": "Root element not registered",
"163": "node is not a ListNode"
}

0 comments on commit 537054f

Please sign in to comment.