File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
custom-highlight-api/highlightsFromPoint Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments