commit 2c833bdbcf7274909b8ca1a9308f77b1022128eb from: Mark Jamsek via: Thomas Adam date: Mon Jul 08 16:17:05 2024 UTC tog: squish horizontal scroll bug that draws trailing '.' When calling span_wline() to compute the number of columns to skip on a string with a column length less than or equal to the number of columns we want to skip (i.e., that the user has scrolled right), the call to wcwidth(3) returns -1 for a '\n', which we replace with a '.' character. Trim trailing newlines before calling span_wline(). ok op@ commit - aed1f7694fc4740d880a503eac8ebe1f6c4f3eca commit + 2c833bdbcf7274909b8ca1a9308f77b1022128eb blob - 04f4fa4c3cfbec150ae760c462178f05c608149e blob + 4801c9c97f0a63d5a0351ee3ab00ca40e143e5f5 --- regress/tog/diff.sh +++ regress/tog/diff.sh @@ -476,6 +476,69 @@ test_diff_commit_keywords() 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_diff_horizontal_scroll() +{ + test_init diff_horizontal_scroll + + local commit_id1=`git_show_head $testroot/repo` + local alpha_id_old=`get_blob_id $testroot/repo "" alpha` + + { + echo -n "01234567890123456789012345678901234567890123456789" + echo "0123456789012345678901234567890123" + } >> $testroot/repo/alpha + + git_commit $testroot/repo -m "scroll" + local author_time=`git_show_author_time $testroot/repo` + local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"` + local head_id=`git_show_head $testroot/repo` + local head_id_truncated=`trim_obj_id 13 $head_id` + local alpha_id=`get_blob_id $testroot/repo "" alpha` + + cat <$TOG_TEST_SCRIPT +3l +SCREENDUMP +EOF + + cat <$testroot/view.expected +[1/20] diff $commit_id1 $head_id_truncated + $head_id (master) +Flan Hacker +$date + + + +ha | 1+ 0- + + changed, 1 insertion(+), 0 deletions(-) + + - $commit_id1 + + $head_id + $alpha_id_old + $alpha_id +pha +pha ++1,2 @@ + +5678901234567890123456789012345678901234567890123456789012345678901234567890123 + + + +(END) +EOF + + cd $testroot/repo && tog diff $commit_id1 $head_id + 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 @@ -488,3 +551,4 @@ run_test test_diff_contiguous_commits run_test test_diff_arbitrary_commits run_test test_diff_J_keymap run_test test_diff_commit_keywords +run_test test_diff_horizontal_scroll blob - 181280f8ea352b18d6cf042612ac8ac22591aaae blob + dc0abc92da9413470fc5f81e57dab2826b4f3289 --- tog/tog.c +++ tog/tog.c @@ -2307,8 +2307,6 @@ format_line(wchar_t **wlinep, int *widthp, int *scroll free(exstr); if (err) return err; - - scrollx = span_wline(&cols, 0, wline, nscroll, col_tab_align); if (wlen > 0 && wline[wlen - 1] == L'\n') { wline[wlen - 1] = L'\0'; @@ -2318,6 +2316,8 @@ format_line(wchar_t **wlinep, int *widthp, int *scroll wline[wlen - 1] = L'\0'; wlen--; } + + scrollx = span_wline(&cols, 0, wline, nscroll, col_tab_align); i = span_wline(&cols, scrollx, wline, wlimit, col_tab_align); wline[i] = L'\0';