jeromepl / highlighter

A Chrome extension to highlight text and keep it all saved
MIT License
308 stars 77 forks source link

Is it possible to remove a highlight instead of changing its look only? #57

Closed gudh closed 1 year ago

gudh commented 1 year ago

https://github.com/jeromepl/highlighter/blob/v4.0.4/src/contentScripts/highlight/remove.js#L13

In remove.js, it updateStorage() rather than removeHighlight()

Is it possible to remove the highlight instead?

jeromepl commented 1 year ago

The reason for this is that it's slightly safer / covers more cases. Because of the way the highlights are stored, they are very dependent on the structure of the html, so much so that they can be affected by previous highlights. So if, for example, the first highlight that was done on the page is deleted, then that might cause all the other highlights that were done to break (as in: the extension wouldn't be able to locate their anchor and focus elements). Simply hiding a highlight instead of removing it makes sure that the HTML is unchanged

If we had a better way of serializing highlight locations that is less tightly coupled to the html structure of the page it would be a net benefit as it could make the extension work on more dynamic webpages, but also would allow us to remove highlights instead of simply hiding them as you found here. Here is the issue I have opened for that, I believe there is a way to make this work but it will require significant effort: https://github.com/jeromepl/highlighter/issues/30