forked from ComputerTech/bastebin
fix: clicking highlighted line number clears the highlight
This commit is contained in:
parent
f93d232769
commit
c8d78c7d61
|
|
@ -260,6 +260,11 @@ function _wireLineClicks() {
|
||||||
_hlStart = a; _hlEnd = b;
|
_hlStart = a; _hlEnd = b;
|
||||||
_drawHighlight(a, b);
|
_drawHighlight(a, b);
|
||||||
_updateLineUrl(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 {
|
} else {
|
||||||
_hlAnchor = lineNum;
|
_hlAnchor = lineNum;
|
||||||
_hlStart = 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) {
|
function _drawHighlight(start, end) {
|
||||||
const viewPre = document.getElementById('viewPre');
|
const viewPre = document.getElementById('viewPre');
|
||||||
const code = document.getElementById('codeBlock');
|
const code = document.getElementById('codeBlock');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue