Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
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.
Diffstat (limited to '')
-rw-r--r--assets/cgit.js5
1 file changed, 3 insertions, 2 deletions
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);