Skip to content

Commit 253a73c

Browse files
authored
change legend and exclude popup from search (#95)
1 parent c923b74 commit 253a73c

File tree

1 file changed

+16
-3
lines changed
  • custom-highlight-api/highlightsFromPoint

1 file changed

+16
-3
lines changed

custom-highlight-api/highlightsFromPoint/index.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ <h2>Highlight Types Legend</h2>
103103
<span class="legend-description">Dark background with white text - API names and technical terms</span>
104104
</div>
105105
<div class="legend-item">
106-
<span class="legend-highlight definition-demo">Definitions (Shadow DOM)</span>
107-
<span class="legend-description">Light blue background with dotted underline - technical definitions, only in shadow DOM content</span>
106+
<span class="legend-highlight definition-demo">Keywords in Shadow DOM</span>
107+
<span class="legend-description">Light blue background with dotted underline - technical keywords in the shadow DOM</span>
108108
</div>
109109
</div>
110110
<p><strong>Hover over any text</strong> to see which highlights are active at that point using CSS.highlights.highlightsFromPoint().</p>
@@ -177,7 +177,20 @@ <h2>Demo source code</h2>
177177
}
178178

179179
const shadowTextNodes = getAllTextNodes(shadowRoot);
180-
const allTextNodes = getAllTextNodes(document.body).concat(shadowTextNodes);
180+
181+
// Get all text nodes from document.body but exclude the popup
182+
const mainTextNodes = getAllTextNodes(document.body).filter(textNode => {
183+
let parent = textNode.parentNode;
184+
while (parent) {
185+
if (parent.id === 'highlight-info') {
186+
return false;
187+
}
188+
parent = parent.parentNode;
189+
}
190+
return true;
191+
});
192+
193+
const allTextNodes = mainTextNodes.concat(shadowTextNodes);
181194

182195
// Function to create highlights for specific words/phrases
183196
function createHighlightsForWords(textNodes, words, highlightName) {

0 commit comments

Comments
 (0)