diff --git a/navigator-html-injectables/src/modules/Decorator.ts b/navigator-html-injectables/src/modules/Decorator.ts index f804aef9..a528926f 100644 --- a/navigator-html-injectables/src/modules/Decorator.ts +++ b/navigator-html-injectables/src/modules/Decorator.ts @@ -103,8 +103,12 @@ class DecorationGroup { // The common ancestor is an element that definitely cannot be highlighted this.notTextFlag?.set(id, true); } - if(ancestor.querySelector(cannotNativeHighlight.join(", ").toLowerCase())) { - // Contains elements that definitely cannot be highlighted as children + // Check if the range itself contains elements that cannot be highlighted + const rangeFragment = range.cloneContents(); + const tempDiv = this.wnd.document.createElement('div'); + tempDiv.appendChild(rangeFragment); + if(tempDiv.querySelector(cannotNativeHighlight.join(", ").toLowerCase())) { + // Range contains elements that definitely cannot be highlighted this.notTextFlag?.set(id, true); } if((ancestor.textContent?.trim() || "").length === 0) {