Skip to content

Commit d46f48c

Browse files
tefkahJayPanoz
andauthored
fix: improve unhighlightable contents check (#170)
Co-authored-by: Jiminy Panoz <JayPanoz@users.noreply.github.com>
1 parent 090afd5 commit d46f48c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

navigator-html-injectables/src/modules/Decorator.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ class DecorationGroup {
103103
// The common ancestor is an element that definitely cannot be highlighted
104104
this.notTextFlag?.set(id, true);
105105
}
106-
if(ancestor.querySelector(cannotNativeHighlight.join(", ").toLowerCase())) {
107-
// Contains elements that definitely cannot be highlighted as children
106+
// Check if the range itself contains elements that cannot be highlighted
107+
const rangeFragment = range.cloneContents();
108+
if(rangeFragment.querySelector(cannotNativeHighlight.join(", ").toLowerCase())) {
109+
// Range contains elements that definitely cannot be highlighted
108110
this.notTextFlag?.set(id, true);
109111
}
110112
if((ancestor.textContent?.trim() || "").length === 0) {

0 commit comments

Comments
 (0)