js: Highlight line of code when start == end

Enable code highlighting when there is only 1 selected line of code.

Signed-off-by: James Raphael Tiovalen <jamestiotio@gmail.com>
This commit is contained in:
James Raphael Tiovalen 2024-10-05 21:17:41 +08:00 committed by Théo Lebrun
parent 4b3d35399d
commit f2146891c9
2 changed files with 5 additions and 5 deletions

View file

@ -133,12 +133,12 @@ function parseLineId(lineId) {
// Parse and validate line range anchor in format #L${lineRangeStart}-L${lineRangeEnd}
function parseLineRangeAnchor(hashStr) {
const hash = hashStr.substring(1).split("-");
if (hash.length != 2) {
if (hash.length < 1 || hash.length > 2) {
return;
}
let firstLine = parseLineId(hash[0]);
let lastLine = parseLineId(hash[1]);
let lastLine = hash.length === 2 ? parseLineId(hash[1]) : parseLineId(hash[0]);
if (firstLine === undefined || lastLine === undefined) {
return;
@ -231,10 +231,10 @@ function setupLineRangeHandlers() {
if (rangeStartLine === undefined || !ev.shiftKey) {
rangeStartLine = parseLineId(el.id);
el.classList.add("line-highlight");
rangeEndLine = undefined;
highlightFromTo(rangeStartLine, rangeStartLine);
window.location.hash = el.id;
} else if(ev.shiftKey) {
} else if (ev.shiftKey) {
if (rangeEndLine === undefined) {
rangeEndLine = parseLineId(el.id);
}

View file

@ -73,7 +73,7 @@
</span>
</footer>
</div>
<script src="/static/script.js?v=13"></script>
<script src="/static/script.js?v=14"></script>
<script src="/static/dynamic-references.js?v=4"></script>
<script src="/static/autocomplete.js" project="{{ current_project }}"></script>
</body>