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

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: adjust line offset when resizing splits
To:
gameoftrees@openbsd.org
Date:
Mon, 11 Jul 2022 02:06:24 +1000

Download raw body.

Thread
Now we can resize splits, we need to adjust the line offset when
increasing/decreasing hsplits otherwise our selection can end up
offscreen because calls to offset_selection_up() rely on a bogus offset.

repro:

$ TOG_VIEW_SPLIT_MODE=h tog  # 80x24
22j
return  # open diff view in a hsplit
tab  # focus log (top) split
10+  # increase top split by 10 lines
22j
return  # open diff view in a hsplit
F  # toggle fullscreen diff view
tab  # focus log (parent) view in fullscreen
# selection cursor will be off the bottom of the screen

This happens because when we increase the top split (or decrease the
bottom split), our log view line offset becomes incorrect (too large) as
it was based on the pre-resized (smaller top split) dimensions. We need
to adjust the offset whenever we resize a split:
  - decrease view->offset when view->nlines increases
  - increase view->offset when view->nlines decreases

diff 3c1dfe12b3f3eae6dc7ef4762772e849794296c5 f90c2b1a692516df9e91e1198067c6ef17f39480
commit - 3c1dfe12b3f3eae6dc7ef4762772e849794296c5
commit + f90c2b1a692516df9e91e1198067c6ef17f39480
blob - 310eb39a0776dd5fb11adc30d6c50fba6d7de13b
blob + b1737c8daf0dfcc8f370ad4f2423e6afd7f09fbe
--- tog/tog.c
+++ tog/tog.c
@@ -927,6 +927,25 @@ view_resize(struct tog_view *view)
 	return NULL;
 }

+static void
+view_adjust_offset(struct tog_view *view, int n)
+{
+	if (n == 0)
+		return;
+
+	if (view->parent) {
+		if (view->parent->offset + n >= 0)
+			view->parent->offset += n;
+		else
+			view->parent->offset = 0;
+	} else {
+		if (view->offset - n >= 0)
+			view->offset -= n;
+		else
+			view->offset = 0;
+	}
+}
+
 static const struct got_error *
 view_resize_split(struct tog_view *view, int resize)
 {
@@ -959,6 +978,7 @@ view_resize_split(struct tog_view *view, int resize)
 		}
 		v->ncols = COLS;
 		v->child->ncols = COLS;
+		view_adjust_offset(view, resize);
 		err = view_init_hsplit(v, v->child->begin_y);
 		if (err)
 			return err;

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