fix(app): preserve node selection when reconciling composer markdown (#1626)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-15 14:07:58 +02:00
1 parent 3df84098e6
commit d0f56c3afd
1 file changed
+16
@@ -19,11 +19,14 @@ import {$isComposerStandardEmojiNode} from '@app/features/lexical/composer/nodes
import {$isSlashSlotNode} from '@app/features/lexical/composer/nodes/SlashSlotNode'; import {$isSlashSlotNode} from '@app/features/lexical/composer/nodes/SlashSlotNode';
import {$createSyntaxMarkerNode, $isSyntaxMarkerNode} from '@app/features/lexical/composer/nodes/SyntaxMarkerNode'; import {$createSyntaxMarkerNode, $isSyntaxMarkerNode} from '@app/features/lexical/composer/nodes/SyntaxMarkerNode';
import { import {
$createNodeSelection,
$createTextNode, $createTextNode,
$getNodeByKey, $getNodeByKey,
$getSelection, $getSelection,
$isLineBreakNode, $isLineBreakNode,
$isNodeSelection,
$isRangeSelection, $isRangeSelection,
$setSelection,
type LexicalEditor, type LexicalEditor,
type LexicalNode, type LexicalNode,
ParagraphNode, ParagraphNode,
@@ -205,8 +208,21 @@ function $reconcileLine(
const selectionKeys = $isRangeSelection(currentSelection) const selectionKeys = $isRangeSelection(currentSelection)
? {anchor: currentSelection.anchor.key, focus: currentSelection.focus.key} ? {anchor: currentSelection.anchor.key, focus: currentSelection.focus.key}
: null; : null;
const nodeSelectionKeys = $isNodeSelection(currentSelection)
? currentSelection.getNodes().map((node) => node.getKey())
: null;
const selection = $captureSelectionOffsets(); const selection = $captureSelectionOffsets();
$applyDescriptors(line, desired); $applyDescriptors(line, desired);
if (nodeSelectionKeys != null) {
if (nodeSelectionKeys.every((key) => $getNodeByKey(key)?.isAttached() === true)) {
const restored = $createNodeSelection();
for (const key of nodeSelectionKeys) {
restored.add(key);
}
$setSelection(restored);
}
return;
}
const anchorNode = selectionKeys == null ? null : $getNodeByKey(selectionKeys.anchor); const anchorNode = selectionKeys == null ? null : $getNodeByKey(selectionKeys.anchor);
const focusNode = selectionKeys == null ? null : $getNodeByKey(selectionKeys.focus); const focusNode = selectionKeys == null ? null : $getNodeByKey(selectionKeys.focus);
const selectionNodesSurvived = const selectionNodesSurvived =