Fix failing insertNodes when selection is null (#5956)

This commit is contained in:
Gerard Rovira
2024-04-24 16:27:29 +01:00
committed by GitHub
parent 387f427d1f
commit 537054f518
2 changed files with 13 additions and 3 deletions

View File

@ -2681,10 +2681,17 @@ export function $getTextContent(): string {
} }
function removeTextAndSplitBlock(selection: RangeSelection): number { function removeTextAndSplitBlock(selection: RangeSelection): number {
let selection_ = selection;
if (!selection.isCollapsed()) { 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( invariant(
$isRangeSelection(selection_), $isRangeSelection(selection_),
'Unexpected dirty selection to be null', 'Unexpected dirty selection to be null',

View File

@ -159,5 +159,8 @@
"157": "Expected tableNode to have a parent TableNode", "157": "Expected tableNode to have a parent TableNode",
"158": "Expected gridParent to have a parent", "158": "Expected gridParent to have a parent",
"159": "Expected focusCellParent 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"
} }