From 6064191ea6b610cb1266f76a40fc7fd243c5cb50 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 5 Sep 2024 17:50:55 +0200 Subject: [PATCH] Remove unnecessary utility function --- src/dom.ts | 6 ------ src/domobserver.ts | 5 ++--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/dom.ts b/src/dom.ts index f3ea4d1..508adcd 100644 --- a/src/dom.ts +++ b/src/dom.ts @@ -15,12 +15,6 @@ export function contains(dom: Node, node: Node | null) { return node ? dom == node || dom.contains(node.nodeType != 1 ? node.parentNode : node) : false } -export function deepActiveElement(doc: Document) { - let elt = doc.activeElement - while (elt && elt.shadowRoot) elt = elt.shadowRoot.activeElement - return elt -} - export function hasSelection(dom: HTMLElement, selection: SelectionRange): boolean { if (!selection.anchorNode) return false try { diff --git a/src/domobserver.ts b/src/domobserver.ts index 0c956a1..bd31338 100644 --- a/src/domobserver.ts +++ b/src/domobserver.ts @@ -2,8 +2,7 @@ import browser from "./browser" import {ContentView, ViewFlag} from "./contentview" import {EditorView} from "./editorview" import {editable, ViewUpdate, setEditContextFormatting, MeasureRequest} from "./extension" -import {hasSelection, getSelection, DOMSelectionState, isEquivalentPosition, - deepActiveElement, dispatchKey, atElementStart} from "./dom" +import {hasSelection, getSelection, DOMSelectionState, isEquivalentPosition, dispatchKey, atElementStart} from "./dom" import {DOMChange, applyDOMChange, applyDOMChangeInner} from "./domchange" import type {EditContext} from "./editcontext" import {Decoration} from "./decoration" @@ -201,7 +200,7 @@ export class DOMObserver { let selection = getSelection(view.root) if (!selection) return false let range = browser.safari && (view.root as any).nodeType == 11 && - deepActiveElement(this.dom.ownerDocument) == this.dom && + view.root.activeElement == this.dom && safariSelectionRangeHack(this.view, selection) || selection if (!range || this.selectionRange.eq(range)) return false let local = hasSelection(this.dom, range)