when trying to highlight search hits that occur in child elements of the content and outside I get this error
minimal reproduction content:
<div class="content">
<p>
<a href="https://lorem.test">Lorem</a> ipsum dolor sit amet, consectetur adipisicing elit.
Adipisci tempora, vero. Aliquid debitis dicta earum est
fugit, hic id iure, libero minima minus modi nesciunt officia velit. Eum, sed, totam.
</p>
</div>
Now search for "lor" and you will get this error in the browser console
IndexSizeError: Failed to execute 'setEnd' on 'Range': There is no child at offset 3.
at getRangesForSearchTermInElement (index.js:70:11)
at index.js:33:24
at Array.forEach (<anonymous>)
at index.js:32:60
at Array.map (<anonymous>)
at highlightSearchTerm (index.js:31:26)
I looked at the code for a bit and I believe the usage of textContent for looking up which terms to select is the root cause, which will aggregate the whole text content of all child nodes. I think it would be better to look up text nodes manually and operate on their values.
I did not try it out yet, though 😦
when trying to highlight search hits that occur in child elements of the content and outside I get this error
minimal reproduction content:
Now search for "lor" and you will get this error in the browser console
I looked at the code for a bit and I believe the usage of textContent for looking up which terms to select is the root cause, which will aggregate the whole text content of all child nodes. I think it would be better to look up text nodes manually and operate on their values.
I did not try it out yet, though 😦