From fea12164dd8f6b579f026ed0612f83dfbc5eb066 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 13:17:37 -0700 Subject: Scroll a line range to where a single line lands The anchors' scroll margin of half the window already centres a line scrolled to the top of the view, which is where the browser puts a single line. Asking to centre a range as well centred the margin with it, and in Chromium, WebKit and Firefox the first line of a range landed 73% of the way down the window against 49% for a single line. --- assets/cgit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'assets') diff --git a/assets/cgit.js b/assets/cgit.js index d09423f..dfe4e3d 100644 --- a/assets/cgit.js +++ b/assets/cgit.js @@ -153,9 +153,10 @@ function place_bar() { table.appendChild(bar); // A browser only scrolls to a fragment that names a real id, which a range - // never does, so bring the start of one into view here. + // never does, so bring the start of one into view here. The scroll margin + // on the anchors centres it the way it centres a single line. if (match[2]) - first.scrollIntoView({ block: "center" }); + first.scrollIntoView(); } document.addEventListener("DOMContentLoaded", place_bar, false); -- cgit