From e5d942bbee1355fa8e285be6b64a43f42a9966e2 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 4 Jun 2022 07:42:07 +0000 Subject: [PATCH] When picking a buffer because one isn't specified by the user, ignore named buffers. GitHub issue 3212 from David le Blanc. --- usr.bin/tmux/cmd-choose-tree.c | 4 ++-- usr.bin/tmux/paste.c | 10 +++++++++- usr.bin/tmux/tmux.h | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/usr.bin/tmux/cmd-choose-tree.c b/usr.bin/tmux/cmd-choose-tree.c index e84c87e3d85..59a63718dcd 100644 --- a/usr.bin/tmux/cmd-choose-tree.c +++ b/usr.bin/tmux/cmd-choose-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-tree.c,v 1.50 2021/08/27 17:25:55 nicm Exp $ */ +/* $OpenBSD: cmd-choose-tree.c,v 1.51 2022/06/04 07:42:07 nicm Exp $ */ /* * Copyright (c) 2012 Thomas Adam @@ -100,7 +100,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item) const struct window_mode *mode; if (cmd_get_entry(self) == &cmd_choose_buffer_entry) { - if (paste_get_top(NULL) == NULL) + if (paste_is_empty()) return (CMD_RETURN_NORMAL); mode = &window_buffer_mode; } else if (cmd_get_entry(self) == &cmd_choose_client_entry) { diff --git a/usr.bin/tmux/paste.c b/usr.bin/tmux/paste.c index 9e257239abf..e23e97aedb3 100644 --- a/usr.bin/tmux/paste.c +++ b/usr.bin/tmux/paste.c @@ -1,4 +1,4 @@ -/* $OpenBSD: paste.c,v 1.42 2020/05/16 15:35:19 nicm Exp $ */ +/* $OpenBSD: paste.c,v 1.43 2022/06/04 07:42:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -112,6 +112,12 @@ paste_walk(struct paste_buffer *pb) return (RB_NEXT(paste_time_tree, &paste_by_time, pb)); } +int +paste_is_empty(void) +{ + return RB_ROOT(&paste_by_time) == NULL; +} + /* Get the most recent automatic buffer. */ struct paste_buffer * paste_get_top(const char **name) @@ -119,6 +125,8 @@ paste_get_top(const char **name) struct paste_buffer *pb; pb = RB_MIN(paste_time_tree, &paste_by_time); + while (pb != NULL && !pb->automatic) + pb = RB_NEXT(paste_time_tree, &paste_by_time, pb); if (pb == NULL) return (NULL); if (name != NULL) diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 7636d28bd8c..cf497afee7a 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1170 2022/05/30 13:02:55 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1171 2022/06/04 07:42:07 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2057,6 +2057,7 @@ u_int paste_buffer_order(struct paste_buffer *); time_t paste_buffer_created(struct paste_buffer *); const char *paste_buffer_data(struct paste_buffer *, size_t *); struct paste_buffer *paste_walk(struct paste_buffer *); +int paste_is_empty(void); struct paste_buffer *paste_get_top(const char **); struct paste_buffer *paste_get_name(const char *); void paste_free(struct paste_buffer *); -- 2.20.1