Support focus anchor button input details in find

The dom.ts is fixed a little to improve type check.
This commit is contained in:
gholk 2022-09-04 15:08:56 +08:00
parent d76ad67fe1
commit 696510a50f
2 changed files with 17 additions and 6 deletions

View file

@ -74,11 +74,20 @@ class FindHighlight extends HTMLSpanElement {
inline: "center",
})
}
let parentNode = this.range.startContainer.parentNode
while (parentNode && !(parentNode instanceof HTMLAnchorElement)) {
parentNode = parentNode.parentNode
let parentElement = this.range.startContainer.parentElement
loop: while (parentElement) {
switch (parentElement.nodeName.toLowerCase()) {
case "a":
case "input":
case "button":
case "details":
parentElement.focus()
break loop
}
parentElement = parentElement.parentElement
}
if (parentNode) parentNode.focus()
for (const node of this.children) {
;(node as HTMLElement).style.background = `rgba(255,127,255,0.5)`
}

View file

@ -222,8 +222,10 @@ export function isVisibleFilter(
*/
export function isVisible(thing: Element | Range) {
while (!(thing.getBoundingClientRect instanceof Function)) {
thing = thing.parentElement
if (thing instanceof Element) {
while (typeof thing.getBoundingClientRect !== "function") {
thing = thing.parentElement
}
}
const clientRect = thing.getBoundingClientRect()
switch (true) {