"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: call resize_log_view() when toggling fullscreen from child diff view
To:
Game of Trees <gameoftrees@openbsd.org>
Date:
Sun, 23 Apr 2023 22:46:35 +1000

Download raw body.

Thread
When toggling fullscreen, we check if the view has a resize() function
pointer to call. We do this for the log view to ensure enough commits
are loaded to populate the view when going from a horizontal split to
fullscreen, for example.

However, we neglected to do this when toggling fullscreen from a child
view if the parent view has the resize() routine; for example, when in
a diff view opened from the log. The first of the two below diffs adds
this check to call view->resize(). This fixes a bug that prevents
scrolling the log from the diff view with the J keymap if on the last
loaded commit. The second diff adds a test for this case.

To reproduce:

  # LINES=24
  tog
  KEY_ENTER	open diff view of selected commit
  S		toggle horizontal split
  TAB		tab back to log view
  23j		move to last loaded commit
  KEY_ENTER	select last loaded commit
  F		toggle fullscreen
  J -> diff view doesn't change because we don't scroll down the log

-----------------------------------------------
commit 1ade25172533e8fa1e38184da39098989fc69142 (main)
from: Mark Jamsek <mark@jamsek.dev>
date: Sun Apr 23 12:41:48 2023 UTC
 
 tog regress: TAB instruction + test for diff J keymap
 
 Add the TAB instruction to the test harness, and a test case for the previous
 commit: scroll down the log from the diff view with the J keymap when on the
 last loaded commit.
 
 M  regress/tog/diff.sh  |  75+  0-
 M  tog/tog.c            |   2+  0-

2 files changed, 77 insertions(+), 0 deletions(-)

diff 1a93a443fe4b154e88d90628a83c4d71a9f7faac 1ade25172533e8fa1e38184da39098989fc69142
commit - 1a93a443fe4b154e88d90628a83c4d71a9f7faac
commit + 1ade25172533e8fa1e38184da39098989fc69142
blob - 04242def3c3bd1f7ec0b24922210fbedced28abb
blob + 53edc5c3c79e0951bfdaf8315a353c3430a7b579
--- regress/tog/diff.sh
+++ regress/tog/diff.sh
@@ -131,6 +131,81 @@ test_parseargs "$@"
 	test_done "$testroot" "$ret"
 }
 
+test_diff_J_keymap_on_last_loaded_commit()
+{
+	test_init diff_J_keymap_on_last_loaded_commit 94 24
+
+	local i=0
+
+	cd $testroot/repo
+
+	while [ "$i" -lt 32 ]; do
+		echo $i > alpha
+		git commit -aqm $i
+		if [ $i -eq 6 ]; then
+			local id6=$(git_show_head .)
+			local blobid6=$(get_blob_id . "" alpha)
+		elif [ $i -eq 7 ]; then
+			local id7=$(git_show_head .)
+			local blobid7=$(get_blob_id . "" alpha)
+			local author_time=$(git_show_author_time .)
+		fi
+		i=$(( i + 1 ))
+	done
+
+	local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
+
+	cat <<EOF >$TOG_TEST_SCRIPT
+KEY_ENTER	open diff view of selected commit
+S		toggle horizontal split
+TAB		tab back to log view
+23j		move to last loaded commit
+KEY_ENTER	select last loaded commit
+F		toggle fullscreen
+J		move down to next commit in the log
+SCREENDUMP
+EOF
+
+	cat <<EOF >$testroot/view.expected
+[1/20] diff $id6 $id7
+commit $id7
+from: Flan Hacker <flan_hacker@openbsd.org>
+date: $date
+
+7
+
+M  alpha  |  1+  1-
+
+1 file changed, 1 insertion(+), 1 deletion(-)
+
+commit - $id6
+commit + $id7
+blob - $blobid6
+blob + $blobid7
+--- alpha
++++ alpha
+@@ -1 +1 @@
+-6
++7
+
+
+
+(END)
+EOF
+
+	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_diff_contiguous_commits
 run_test test_diff_arbitrary_commits
+run_test test_diff_J_keymap_on_last_loaded_commit
blob - 3be11e9258a6e79e8c65c51e4201e2fe72b26653
blob + 09cd112bc1ff0346edd8a4dd37b64c38e1d41113
--- tog/tog.c
+++ tog/tog.c
@@ -1649,6 +1649,8 @@ tog_read_script_key(FILE *script, struct tog_view *vie
 		*ch = KEY_DOWN;
 	else if (strncasecmp(line, "KEY_UP", 6) == 0)
 		*ch = KEY_UP;
+	else if (strncasecmp(line, "TAB", 3) == 0)
+		*ch = '\t';
 	else if (strncasecmp(line, "SCREENDUMP", 10) == 0)
 		*ch = TOG_KEY_SCRDUMP;
 	else if (isdigit((unsigned char)*line)) {

-----------------------------------------------
commit 1a93a443fe4b154e88d90628a83c4d71a9f7faac
from: Mark Jamsek <mark@jamsek.dev>
date: Sun Apr 23 10:37:53 2023 UTC
 
 tog: resize log view if toggling fullscreen from child view
 
 We call resize_log_view() when toggling 'F'ullscreen from the log view, but
 forgot to do this when toggling fullscreen from a child view if its parent
 is the log view. This fixes a bug that prevents scrolling down the log view
 from the diff view with the J keymap if already on the last loaded commit.
 Regress test in the following commit.
 
 M  tog/tog.c  |  10+  3-

1 file changed, 10 insertions(+), 3 deletions(-)

diff 91db220264b6d9be6d44223dd76ae8eb9bea3641 1a93a443fe4b154e88d90628a83c4d71a9f7faac
commit - 91db220264b6d9be6d44223dd76ae8eb9bea3641
commit + 1a93a443fe4b154e88d90628a83c4d71a9f7faac
blob - 51d1e270d8a161220288c3ad69268b9b6e7d0beb
blob + 3be11e9258a6e79e8c65c51e4201e2fe72b26653
--- tog/tog.c
+++ tog/tog.c
@@ -1852,10 +1852,17 @@ view_input(struct tog_view **new, int *done, struct to
 			if (err)
 				break;
 		}
-		if (view->parent)
+		if (view->parent) {
+			if (view->parent->resize) {
+				err = view->parent->resize(view->parent, 0);
+				if (err != NULL)
+					break;
+			}
 			err = offset_selection_down(view->parent);
-		if (!err)
-			err = offset_selection_down(view);
+			if (err != NULL)
+				break;
+		}
+		err = offset_selection_down(view);
 		break;
 	case 'S':
 		view->count = 0;


-- 
Mark Jamsek <fnc.bsdbox.org|got.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68