commit fe354d70d4ad218c599cac447058537d734836e5 from: Mark Jamsek via: Thomas Adam date: Fri Jan 3 10:46:48 2025 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 - 9976affb503011ab063f1de78688b26414d8ec9a commit + fe354d70d4ad218c599cac447058537d734836e5 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 - 879259f6229b008b4113a82b1138cd2193670ee0 blob + 2f26d13b606488dfcb50b4273bb71e143d93b757 --- tog/tog.c +++ tog/tog.c @@ -11469,7 +11469,7 @@ offset_selection_down(struct tog_view *view) view->offset = offset; if (scrolld && offset) { err = scrolld(view, offset); - *selected -= offset; + *selected -= MIN(*selected, offset); } }