Move deepestShadowRoot to lib/dom to allow reuse

This commit is contained in:
Oliver Blanthorn 2020-08-02 12:46:18 +01:00
parent 49b6e727f3
commit 465913f4be
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 12 additions and 10 deletions

View file

@ -3,6 +3,7 @@ import { contentState, ModeName } from "@src/content/state_content"
import Logger from "@src/lib/logging"
import * as controller from "@src/lib/controller"
import { KeyEventLike, ParserResponse } from "@src/lib/keyseq"
import { deepestShadowRoot } from "@src/lib/dom"
import * as hinting from "@src/content/hinting"
import * as gobblemode from "@src/parsers/gobblemode"
@ -93,16 +94,6 @@ class KeyCanceller {
export const canceller = new KeyCanceller()
/** Recursively resolves an active shadow DOM element. */
function deepestShadowRoot(sr: ShadowRoot|null): ShadowRoot|null {
if (sr === null) return sr
let shadowRoot = sr
while (shadowRoot.activeElement.shadowRoot != null) {
shadowRoot = shadowRoot.activeElement.shadowRoot
}
return shadowRoot
}
/** Accepts keyevents, resolves them to maps, maps to exstrs, executes exstrs */
function* ParserController() {
const parsers: {

View file

@ -683,3 +683,14 @@ export function simulateClick(target: HTMLElement) {
focus(target)
}
}
/** Recursively resolves an active shadow DOM element. */
export function deepestShadowRoot(sr: ShadowRoot|null): ShadowRoot|null {
if (sr === null) return sr
let shadowRoot = sr
while (shadowRoot.activeElement.shadowRoot != null) {
shadowRoot = shadowRoot.activeElement.shadowRoot
}
return shadowRoot
}