Merge pull request #3084 from tonywu6/master

Fix: Remove `?highlight=` from URL when highlights are dismissed via clicking
This commit is contained in:
Eric Huss 2026-05-13 14:15:33 +00:00 committed by GitHub
commit 1e04de75e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View file

@ -341,6 +341,9 @@ window.search = window.search || {};
marker.unmark(); marker.unmark();
}, 300); }, 300);
} }
// also removes the `?URL_MARK_PARAM=` search param so that
// in-page navigation doesn't make highlights unexpectedly appear again
setSearchUrlParameters('', 'replace');
}; };
for (let i = 0; i < markers.length; i++) { for (let i = 0; i < markers.length; i++) {

View file

@ -74,3 +74,24 @@ assert: "#mdbook-searchresults"
// And now we press `Escape` to close everything. // And now we press `Escape` to close everything.
press-key: 'Escape' press-key: 'Escape'
wait-for-css: ("#mdbook-search-wrapper", {"display": "none"}) wait-for-css: ("#mdbook-search-wrapper", {"display": "none"})
// Search result links should have a `?highlight=` query param, which will highlight
// the search term when we navigate to the destination page.
go-to: |DOC_PATH| + "search/index.html?search=kale"
assert: '[href*="highlight=kale"]'
// On navigation, text on the destination page that matches the search term should be highlighted.
go-to: |DOC_PATH| + "search/index.html?highlight=kale"
wait-for: '[data-markjs="true"]'
assert-text: ('[data-markjs="true"]', "kale", ALL)
// Clicking on any of the highlights should dismiss them.
click: '[data-markjs="true"]'
assert-false: '[data-markjs="true"]'
// The `?highlight=` URL query param should also have been removed
// (so that highlights don't unexpectedly appear again.)
assert-window-property-false: ({"location": "highlight=kale"}, CONTAINS)
// Verify this by clicking on a heading to navigate to its anchor. This would otherwise preserve
// search params, and if the query param were not removed, highlights would appear again.
click: 'main h1 a'
assert-false: '[data-markjs="true"]'