From 81b15bda9deeea4be497eaaec8829cc4be748b0a Mon Sep 17 00:00:00 2001 From: zhangtiefeng02 Date: Wed, 15 Feb 2023 20:01:48 +0800 Subject: [PATCH] Prevent model selection synchronizing to DOMSelection during selection. --- src/domobserver.ts | 3 +++ src/selection.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/domobserver.ts b/src/domobserver.ts index 027bd385..72f52807 100644 --- a/src/domobserver.ts +++ b/src/domobserver.ts @@ -43,6 +43,7 @@ export class DOMObserver { currentSelection = new SelectionState onCharData: ((e: Event) => void) | null = null suppressingSelectionUpdates = false + lockDOMSelectionSync = false constructor( readonly view: EditorView, @@ -132,7 +133,9 @@ export class DOMObserver { if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode!, sel.anchorOffset)) return this.flushSoon() } + this.lockDOMSelectionSync = !!this.view.input.mouseDown this.flush() + this.lockDOMSelectionSync = false } setCurSelection() { diff --git a/src/selection.ts b/src/selection.ts index 4cb7b791..e5baeb69 100644 --- a/src/selection.ts +++ b/src/selection.ts @@ -64,7 +64,7 @@ export function selectionToDOM(view: EditorView, force = false) { if (view.cursorWrapper) { selectCursorWrapper(view) - } else { + } else if (!view.domObserver.lockDOMSelectionSync) { let {anchor, head} = sel, resetEditableFrom, resetEditableTo if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection)) { if (!sel.$from.parent.inlineContent)