Text Fragments: Correctly find text fragments if there are DOM changes during page load.
Before this patch, the first call to Document::ScrollToRef()
would attempt to find all text directives in the document, and, if found, highlight + scroll to them. Then, it would clear the list of uninvoked directives.
However, ScrollToRef()
is called multiple times during a page load, and the DOM can change (e.g. if DOMContentLoaded
does some changes).
This patch fixes this by only removing the text directives which were found in the document from the list of uninvoked directives.
This way, subsequent calls to ScrollToRef()
would ensure that all text directives are highlighted, and the first text directive is scrolled to.
Additionally, all remaining uninvoked text directives at the end of a page load (ie. text directives that are not on the page) are cleared.
A test was added as well.
Differential Revision: https://phabricator.services.mozilla.com/D211260
bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1898321
gecko-commit: 986a6317351d0690fa5f059b2a00a8248d990fe9
gecko-reviewers: farre, dom-core