Skip to content

Commit

Permalink
Only update selection in unfocused editor when it's not focusable
Browse files Browse the repository at this point in the history
FIX: Avoid spurious focus events by not updating the DOM selection when
the editor is unfocused but focusable.

Issue codemirror/dev#1490
  • Loading branch information
marijnh committed Dec 9, 2024
1 parent fe57aed commit c946a84
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/docview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c946a84

Please sign in to comment.