Download raw body.
fix tog horizontal scroll bug
Because we call span_wline() to compute how many wchar_t characters (i.e., columns) to skip when rendering the diff view before trimming the trailing L'\n', we replace the L'\n' character with L'\.' as wcwidth(3) returns -1 for non-printables. To fix this, move the span_wline() call that finds the offset to after the newline has been trimmed. The added regress test is a good way to visualise the problem if you run the test before building the new tog binary. I stumbled over this by chance when scrolling a diff view with a very short log message. But it also shows in short diff lines too, which the test case evinces. In my tree, this commit is on top of the diff in my previous mail but it might apply cleanly without it. ok? ----------------------------------------------- commit 120adca094fefee3861946acd5d233f7207c3d1b from: Mark Jamsek <mark@jamsek.dev> date: Tue Jul 2 13:35:38 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(). M regress/tog/diff.sh | 64+ 0- M tog/tog.c | 2+ 2- 2 files changed, 66 insertions(+), 2 deletions(-) diff 9edd7675a0eaa4433ac94be5e8f2c0c95abc1042 120adca094fefee3861946acd5d233f7207c3d1b commit - 9edd7675a0eaa4433ac94be5e8f2c0c95abc1042 commit + 120adca094fefee3861946acd5d233f7207c3d1b blob - 04f4fa4c3cfbec150ae760c462178f05c608149e blob + 4801c9c97f0a63d5a0351ee3ab00ca40e143e5f5 --- regress/tog/diff.sh +++ regress/tog/diff.sh @@ -483,8 +483,72 @@ test_diff_commit_keywords() 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 <<EOF >$TOG_TEST_SCRIPT +3l +SCREENDUMP +EOF + + cat <<EOF >$testroot/view.expected +[1/20] diff $commit_id1 $head_id_truncated + $head_id (master) +Flan Hacker <flan_hacker@openbsd.org> +$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 + + test_done "$testroot" "$ret" +} + test_parseargs "$@" 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 - b8146cfeb30ec9156a8c21c672e2e62f2b8666cd blob + 38cb4a714d73a34d03df0760e883cf0196000dbc --- tog/tog.c +++ tog/tog.c @@ -2304,8 +2304,6 @@ format_line(wchar_t **wlinep, int *widthp, int *scroll 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'; wlen--; @@ -2315,6 +2313,8 @@ format_line(wchar_t **wlinep, int *widthp, int *scroll 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'; -- Mark Jamsek <https://bsdbox.org> GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68
fix tog horizontal scroll bug