diff --git a/static/js/paste_view.js b/static/js/paste_view.js index acf1290..cf2b0fb 100644 --- a/static/js/paste_view.js +++ b/static/js/paste_view.js @@ -260,6 +260,11 @@ function _wireLineClicks() { _hlStart = a; _hlEnd = b; _drawHighlight(a, b); _updateLineUrl(a, b); + } else if (_hlStart === lineNum && _hlEnd === lineNum) { + // Clicking the sole highlighted line → clear + _hlAnchor = null; _hlStart = null; _hlEnd = null; + _clearHighlight(); + _clearLineUrl(); } else { _hlAnchor = lineNum; _hlStart = lineNum; @@ -271,6 +276,21 @@ function _wireLineClicks() { }); } +function _clearHighlight() { + const viewPre = document.getElementById('viewPre'); + if (!viewPre) return; + viewPre.querySelectorAll('.line-hl').forEach(el => el.remove()); + viewPre.querySelectorAll('.line-numbers-rows > span').forEach( + s => s.classList.remove('hl-active') + ); +} + +function _clearLineUrl() { + const url = new URL(window.location.href); + url.searchParams.delete('L'); + history.replaceState(null, '', url.toString()); +} + function _drawHighlight(start, end) { const viewPre = document.getElementById('viewPre'); const code = document.getElementById('codeBlock');