From c946a847d8d0b5a7538397a1f32474e34cf34429 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 9 Dec 2024 13:58:07 +0100 Subject: [PATCH] Only update selection in unfocused editor when it's not focusable FIX: Avoid spurious focus events by not updating the DOM selection when the editor is unfocused but focusable. Issue https://github.com/codemirror/dev/issues/1490 --- src/docview.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/docview.ts b/src/docview.ts index cbf85b8..70b67b0 100644 --- a/src/docview.ts +++ b/src/docview.ts @@ -9,7 +9,7 @@ import {getAttrs} from "./attributes" import {clientRectsFor, isEquivalentPosition, Rect, scrollRectIntoView, getSelection, hasSelection, textRange, DOMSelectionState, textNodeBefore, textNodeAfter} from "./dom" -import {ViewUpdate, decorations as decorationsFacet, outerDecorations, ChangedRange, +import {ViewUpdate, decorations as decorationsFacet, outerDecorations, ChangedRange, editable, ScrollTarget, scrollHandler, getScrollMargins, logException, setEditContextFormatting} from "./extension" import {EditorView} from "./editorview" import {Direction} from "./bidi" @@ -228,7 +228,7 @@ export class DocView extends ContentView { updateSelection(mustRead = false, fromPointer = false) { if (mustRead || !this.view.observer.selectionRange.focusNode) this.view.observer.readSelectionRange() let activeElt = this.view.root.activeElement, focused = activeElt == this.dom - let selectionNotFocus = !focused && + let selectionNotFocus = !focused && !(this.view.state.facet(editable) || this.dom.tabIndex > -1) && hasSelection(this.dom, this.view.observer.selectionRange) && !(activeElt && this.dom.contains(activeElt)) if (!(focused || fromPointer || selectionNotFocus)) return let force = this.forceSelection