1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-04 15:25:38 -08:00

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.
This commit is contained in:
nicm 2024-08-04 08:53:43 +00:00
parent 00b011bc21
commit d32785554e
3 changed files with 19 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $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>
@ -261,19 +261,21 @@ mode_tree_up(struct mode_tree_data *mtd, int wrap)
}
}
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 *

View File

@ -1,4 +1,4 @@
/* $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>
@ -3138,7 +3138,7 @@ int mode_tree_set_current(struct mode_tree_data *, uint64_t);
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 *,

View File

@ -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);
}