aboutsummaryrefslogtreecommitdiff
path: root/mode-tree.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2017-09-10 11:39:45 +0100
committerThomas Adam <thomas@xteddy.org>2017-09-10 11:39:45 +0100
commit7f83b53027c98589b516c4137a2fbc48a70e230b (patch)
tree87ea32d30c8dc7f8844e0f9d19a99e967fb92d2c /mode-tree.c
parentc62cfe64c8aabd91ea977950b63a3bc956015143 (diff)
parent8405fcdd9b62e22003923a22edfefdaf42883a98 (diff)
downloadrtmux-7f83b53027c98589b516c4137a2fbc48a70e230b.tar.gz
rtmux-7f83b53027c98589b516c4137a2fbc48a70e230b.tar.bz2
rtmux-7f83b53027c98589b516c4137a2fbc48a70e230b.zip
Merge branch 'obsd-master'
Conflicts: server-client.c
Diffstat (limited to 'mode-tree.c')
-rw-r--r--mode-tree.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/mode-tree.c b/mode-tree.c
index fc31592a..ad783bb4 100644
--- a/mode-tree.c
+++ b/mode-tree.c
@@ -128,6 +128,17 @@ mode_tree_free_items(struct mode_tree_list *mtl)
}
static void
+mode_tree_check_selected(struct mode_tree_data *mtd)
+{
+ /*
+ * If the current line would now be off screen reset the offset to the
+ * last visible line.
+ */
+ if (mtd->current > mtd->height - 1)
+ mtd->offset = mtd->current - mtd->height + 1;
+}
+
+static void
mode_tree_clear_lines(struct mode_tree_data *mtd)
{
free(mtd->line_list);
@@ -192,7 +203,7 @@ mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
if (i != mtd->line_size) {
mtd->current = i;
if (mtd->current > mtd->height - 1)
- mtd->offset = 1 + mtd->current - mtd->height;
+ mtd->offset = mtd->current - mtd->height + 1;
else
mtd->offset = 0;
} else {
@@ -361,6 +372,7 @@ mode_tree_build(struct mode_tree_data *mtd)
mtd->height = screen_size_y(s);
} else
mtd->height = screen_size_y(s);
+ mode_tree_check_selected(mtd);
}
static void
@@ -792,7 +804,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
case KEYC_END:
mtd->current = mtd->line_size - 1;
if (mtd->current > mtd->height - 1)
- mtd->offset = mtd->current - mtd->height;
+ mtd->offset = mtd->current - mtd->height + 1;
else
mtd->offset = 0;
break;
@@ -870,15 +882,8 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
case 'v':
mtd->preview = !mtd->preview;
mode_tree_build(mtd);
-
- /*
- * If the current line would now be off screen now the preview
- * is on, reset the the offset to the last visible line.
- */
- if (mtd->preview && mtd->current > mtd->height - 1) {
- mtd->offset = mtd->current - mtd->height;
- mtd->current--;
- }
+ if (mtd->preview)
+ mode_tree_check_selected(mtd);
break;
}
return (0);