diff --git a/CHANGES.rst b/CHANGES.rst index cd36d83957b..99b6557e5fc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -140,6 +140,8 @@ Bugs fixed * #14059: LaTeX: Footnotes cause pdflatex error with French language (since late June 2025 upstream change to LaTeX ``babel-french``). Patch by Jean-François B. +* #13916: HTML Search: do not clear text fragments from the URL on page load. + Patch by Harmen Stoppels. Testing diff --git a/sphinx/themes/basic/static/sphinx_highlight.js b/sphinx/themes/basic/static/sphinx_highlight.js index ce735d52ee4..a74e103a831 100644 --- a/sphinx/themes/basic/static/sphinx_highlight.js +++ b/sphinx/themes/basic/static/sphinx_highlight.js @@ -80,8 +80,12 @@ const SphinxHighlight = { || url.searchParams.get("highlight") || ""; localStorage.removeItem("sphinx_highlight_terms"); - url.searchParams.delete("highlight"); - window.history.replaceState({}, "", url); + // Update history only if '?highlight' is present; otherwise it + // clears text fragments (not set in window.location by the browser) + if (url.searchParams.has("highlight")) { + url.searchParams.delete("highlight"); + window.history.replaceState({}, "", url); + } // get individual terms from highlight string const terms = highlight