-/* $OpenBSD: mode-tree.c,v 1.67 2024/05/24 12:39:06 nicm Exp $ */
+/* $OpenBSD: mode-tree.c,v 1.68 2024/08/04 08:53:43 nicm Exp $ */
/*
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
}
}
-void
+int
mode_tree_down(struct mode_tree_data *mtd, int wrap)
{
if (mtd->current == mtd->line_size - 1) {
if (wrap) {
mtd->current = 0;
mtd->offset = 0;
- }
+ } else
+ return (0);
} else {
mtd->current++;
if (mtd->current > mtd->offset + mtd->height - 1)
mtd->offset++;
}
+ return (1);
}
void *
-/* $OpenBSD: tmux.h,v 1.1219 2024/07/12 11:21:18 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1220 2024/08/04 08:53:43 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
void mode_tree_each_tagged(struct mode_tree_data *, mode_tree_each_cb,
struct client *, key_code, int);
void mode_tree_up(struct mode_tree_data *, int);
-void mode_tree_down(struct mode_tree_data *, int);
+int mode_tree_down(struct mode_tree_data *, int);
struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *,
mode_tree_build_cb, mode_tree_draw_cb, mode_tree_search_cb,
mode_tree_menu_cb, mode_tree_height_cb, mode_tree_key_cb, void *,
-/* $OpenBSD: window-buffer.c,v 1.39 2024/08/04 08:39:38 nicm Exp $ */
+/* $OpenBSD: window-buffer.c,v 1.40 2024/08/04 08:53:43 nicm Exp $ */
/*
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
struct window_buffer_itemdata *item = itemdata;
struct paste_buffer *pb;
- if (item == mode_tree_get_current(data->data))
- mode_tree_down(data->data, 0);
+ if (item == mode_tree_get_current(data->data) &&
+ !mode_tree_down(data->data, 0)) {
+ /*
+ *If we were unable to select the item further down we are at
+ * the end of the list. Move one element up instead, to make
+ * sure that we preserve a valid selection or we risk having
+ * the tree build logic reset it to the first item.
+ */
+ mode_tree_up(data->data, 0);
+ }
+
if ((pb = paste_get_name(item->name)) != NULL)
paste_free(pb);
}