mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 13:35:42 +09:00
fix(app): preserve node selection when reconciling composer markdown (#1626)
This commit is contained in:
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 =
|
||||||
|
|||||||
Reference in new issue
Block a user