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. --- tests/t0005-markup.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/t0005-markup.sh') diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh index 1a8c5f2..f93392d 100755 --- a/tests/t0005-markup.sh +++ b/tests/t0005-markup.sh @@ -168,6 +168,14 @@ test_expect_success 'the script walks the ages from a list that holds still' ' ! grep "getElementsByClassName" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js" ' +# The line anchors carry a scroll margin of half the window, which centres a +# line scrolled to the top of the view. Asking scrollIntoView to centre it as +# well centres the margin too and drops a range three quarters of the way down. +test_expect_success 'a line range scrolls where a single line does' ' + grep "^ scroll-margin-top: calc(50vh - 1em);$" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" && + grep "first.scrollIntoView();" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js" +' + # The rest of the hooks need a tag, a symlink, a submodule, a trailer, a lone # carriage return, clone urls, an empty repository and a second page of # repositories, so they get a commit and a config of their own after the checks -- cgit