Fix undo selection bug (#517)

This commit is contained in:
Dominic Gannaway
2021-07-27 17:43:32 +01:00
committed by acywatson
parent ed75ebc44b
commit 0cf9ac6b49
2 changed files with 8 additions and 3 deletions

View File

@ -31,8 +31,13 @@ function getMergeAction(
if (prevViewModel === null) { if (prevViewModel === null) {
return NO_MERGE; return NO_MERGE;
} }
const selection = nextViewModel._selection;
const prevSelection = prevViewModel._selection;
const hasDirtyNodes = nextViewModel.hasDirtyNodes(); const hasDirtyNodes = nextViewModel.hasDirtyNodes();
if (!hasDirtyNodes) { if (!hasDirtyNodes) {
if (prevSelection === null && selection !== null) {
return MERGE;
}
return DISCARD; return DISCARD;
} }
const dirtyNodes = nextViewModel.getDirtyNodes(); const dirtyNodes = nextViewModel.getDirtyNodes();
@ -59,8 +64,6 @@ function getMergeAction(
// Only merge if we're adding/removing a single character // Only merge if we're adding/removing a single character
// or if there is not change at all. // or if there is not change at all.
if (textDiff === -1 || textDiff === 1) { if (textDiff === -1 || textDiff === 1) {
const selection = nextViewModel._selection;
const prevSelection = prevViewModel._selection;
if (selection == null || prevSelection === null) { if (selection == null || prevSelection === null) {
return MERGE; return MERGE;
} }

View File

@ -44,5 +44,7 @@
"42": "Reconciliation: could not find DOM element for node key \"${key}\"", "42": "Reconciliation: could not find DOM element for node key \"${key}\"",
"43": "resolveNonLineBreakOrInertNode: resolved node not a text node", "43": "resolveNonLineBreakOrInertNode: resolved node not a text node",
"44": "Extraneous keys in serialized node data: %s", "44": "Extraneous keys in serialized node data: %s",
"45": "OutlineNode: Node type %s does not implement deserialize()." "45": "OutlineNode: Node type %s does not implement deserialize().",
"46": "getAnchorNode: anchorNode not a valid anchor node",
"47": "getFocusNode: focusNode not a valid focus node"
} }