diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-08-04 08:53:44 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-08-04 08:53:44 +0000 |
commit | cc4bbbc512b54efdc0ecb09d191790295858e873 (patch) | |
tree | 90d607b94db604bc2fd05e0eac0841391bb955aa /usr.bin/tmux/window-buffer.c | |
parent | d93ba11b8f9084529d3fe1d964c3330a8b9f9b07 (diff) |
Adjust the logic when deleting last buffer to better preserve the
selection: if selecting the element below the deleted one fails (because
as the last one), select the one above it instead. From Daniel Mueller,
GitHub issue 4043.
Diffstat (limited to 'usr.bin/tmux/window-buffer.c')
-rw-r--r-- | usr.bin/tmux/window-buffer.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/usr.bin/tmux/window-buffer.c b/usr.bin/tmux/window-buffer.c index 28dcef5ec84..185faf9ebc8 100644 --- a/usr.bin/tmux/window-buffer.c +++ b/usr.bin/tmux/window-buffer.c @@ -1,4 +1,4 @@ -/* $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> @@ -408,8 +408,17 @@ window_buffer_do_delete(void *modedata, void *itemdata, 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); } |