commit 919e5e7241ba484d4893ddf26b9c6f21877be3b5 from: Mark Jamsek date: Tue Dec 31 14:05:44 2024 UTC tog: clamp selected idx to avoid showing negative indexes In the rare case views are smaller in height than the first line number after the view's header lines (i.e., [2,5] depending on the view), we can decrement the selected entry index into negative values; clamp it to 0. Add a log view test case covering this path by opening a child tree view and toggling fullscreen. ok stsp@ commit - b7045a4dd319c7794f8b3e7fcec3cf1fa06be040 commit + 919e5e7241ba484d4893ddf26b9c6f21877be3b5 blob - 01a33201435af4ba4c618c10db784372be30bea2 blob + 77e67c8632bd152393715a611f8d74a820e0e3c5 --- regress/tog/log.sh +++ regress/tog/log.sh @@ -1101,7 +1101,39 @@ test_log_worktree_entries() test_done "$testroot" 0 } + +test_log_tiny_child_tree_view() +{ + test_init log_tiny_child_tree_view 120 3 + + local id=$(git_show_head $testroot/repo) + + # This test covers the offset_selection_down() path ensuring + # indexes are properly clamped to prevent negative values. + cat <<-EOF >$TOG_TEST_SCRIPT + T open tree view in vsplit + F toggle fullscreen to hit offset_selection_down() + SCREENDUMP + EOF + cat <<-EOF >$testroot/view.expected + commit $id + [1/4] / + + EOF + + cd $testroot/repo && tog log + cmp -s $testroot/view.expected $testroot/view + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/view.expected $testroot/view + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + test_parseargs "$@" run_test test_log_hsplit_diff run_test test_log_vsplit_diff @@ -1116,3 +1148,4 @@ run_test test_log_limit_view run_test test_log_search run_test test_log_mark_keymap run_test test_log_worktree_entries +run_test test_log_tiny_child_tree_view blob - e8031edb015e8f848ba06221e89e864108afdd00 blob + 8d227eff283fc8287e36b66f666eb4a49d584018 --- tog/tog.c +++ tog/tog.c @@ -11465,7 +11465,7 @@ offset_selection_down(struct tog_view *view) view->offset = offset; if (scrolld && offset) { err = scrolld(view, offset); - *selected -= offset; + *selected -= MIN(*selected, offset); } }