|
1 | 1 | import { Locator } from "@readium/shared"; |
2 | 2 | import { Comms } from "../comms/comms"; |
3 | | -import { Module } from "./Module"; |
4 | | -import { rangeFromLocator } from "../helpers/locator"; |
5 | | -import { ModuleName } from "./ModuleLibrary"; |
6 | | -import { Rect, getClientRectsNoOverlap } from "../helpers/rect"; |
| 3 | +import { isDarkColor } from "../helpers/color"; |
7 | 4 | import { getProperty } from "../helpers/css"; |
8 | 5 | import { ReadiumWindow } from "../helpers/dom"; |
9 | | -import { isDarkColor } from "../helpers/color"; |
| 6 | +import { rangeFromLocator } from "../helpers/locator"; |
| 7 | +import { Rect, getClientRectsNoOverlap } from "../helpers/rect"; |
| 8 | +import { Module } from "./Module"; |
| 9 | +import { ModuleName } from "./ModuleLibrary"; |
10 | 10 |
|
11 | 11 | export enum Width { |
12 | 12 | Wrap = "wrap", // Smallest width fitting the CSS border box. |
@@ -103,8 +103,12 @@ class DecorationGroup { |
103 | 103 | // The common ancestor is an element that definitely cannot be highlighted |
104 | 104 | this.notTextFlag?.set(id, true); |
105 | 105 | } |
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 | + const tempDiv = this.wnd.document.createElement('div'); |
| 109 | + tempDiv.appendChild(rangeFragment); |
| 110 | + if(tempDiv.querySelector(cannotNativeHighlight.join(", ").toLowerCase())) { |
| 111 | + // Range contains elements that definitely cannot be highlighted |
108 | 112 | this.notTextFlag?.set(id, true); |
109 | 113 | } |
110 | 114 | if((ancestor.textContent?.trim() || "").length === 0) { |
|
0 commit comments