From 4991b50c275c3e0b01cd311ac46123dbda5a4a43 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 14 May 2024 07:40:39 +0000 Subject: [PATCH] Add an option to disable unwrapping lines for searching, from meanderingprogrammer at gmail dot com, GitHub issue 3975. --- usr.bin/tmux/options-table.c | 10 +++++++++- usr.bin/tmux/tmux.1 | 12 ++++++++++-- usr.bin/tmux/window-copy.c | 14 ++++++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index 919c7ce1f3f..998e2764ff8 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.171 2024/04/10 07:36:25 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.172 2024/05/14 07:40:39 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -384,6 +384,14 @@ const struct options_table_entry options_table[] = { .text = "Maximum number of commands to keep in history." }, + { .name = "search-wrapped-lines", + .type = OPTIONS_TABLE_FLAG, + .scope = OPTIONS_TABLE_SERVER, + .default_num = 1, + .text = "Whether to include full wrapped lines when searching for " + "text in copy mode." + }, + { .name = "set-clipboard", .type = OPTIONS_TABLE_CHOICE, .scope = OPTIONS_TABLE_SERVER, diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 83e1f119364..d29565f39e6 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.941 2024/04/10 07:36:25 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.942 2024/05/14 07:40:39 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 10 2024 $ +.Dd $Mdocdate: May 14 2024 $ .Dt TMUX 1 .Os .Sh NAME @@ -3795,6 +3795,14 @@ each client. .It Ic prompt-history-limit Ar number Set the number of history items to save in the history file for each type of command prompt. +.It Xo Ic search-wrapped-lines +.Op Ic on | off +.Xc +Defines how +.Nm +handles wrapped lines when searching in copy mode. +When disabled, lines are truncated and searching is faster, but matches may be +missed. .It Xo Ic set-clipboard .Op Ic on | external | off .Xc diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 6c43d4010d0..85c981f7d68 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.348 2024/04/23 13:34:51 jsg Exp $ */ +/* $OpenBSD: window-copy.c,v 1.349 2024/05/14 07:40:39 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -3615,11 +3615,13 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd, int direction, int regex) { u_int i, px, sx, ssize = 1; - int found = 0, cflags = REG_EXTENDED; + int wrapped, found = 0, cflags = REG_EXTENDED; char *sbuf; regex_t reg; struct grid_line *gl; + wrapped = options_get_number(global_options, "search-wrapped-lines"); + if (regex) { sbuf = xmalloc(ssize); sbuf[0] = '\0'; @@ -3636,7 +3638,9 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd, if (direction) { for (i = fy; i <= endline; i++) { gl = grid_get_line(gd, i); - if (i != endline && gl->flags & GRID_LINE_WRAPPED) + if (!wrapped && + i != endline && + gl->flags & GRID_LINE_WRAPPED) continue; if (regex) { found = window_copy_search_lr_regex(gd, @@ -3652,7 +3656,9 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd, } else { for (i = fy + 1; endline < i; i--) { gl = grid_get_line(gd, i - 1); - if (i != endline && gl->flags & GRID_LINE_WRAPPED) + if (!wrapped && + i != endline && + gl->flags & GRID_LINE_WRAPPED) continue; if (regex) { found = window_copy_search_rl_regex(gd, -- 2.20.1