diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-01-08 08:22:11 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-01-08 08:22:11 +0000 |
commit | c484103b5ffa32eb4536fd9924b07ce1768fe12f (patch) | |
tree | cce17cce1cd921ea186d2d78354de1f2c5504399 /usr.bin | |
parent | c8e9e3a8a13b7a67eed0506692a72941ed2f9e5b (diff) |
With incremental search, start empty and only repeat the previous search
if the user tries to search again with an empty prompt. This matches
emacs behaviour more closely.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/status.c | 48 | ||||
-rw-r--r-- | usr.bin/tmux/window-copy.c | 6 |
2 files changed, 37 insertions, 17 deletions
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index e23c612842c..f0e3eed1277 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.218 2020/07/27 08:03:10 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.219 2021/01/08 08:22:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -543,7 +543,7 @@ status_prompt_set(struct client *c, struct cmd_find_state *fs, prompt_free_cb freecb, void *data, int flags) { struct format_tree *ft; - char *tmp, *cp; + char *tmp; if (fs != NULL) ft = format_create_from_state(NULL, c, fs); @@ -563,7 +563,13 @@ status_prompt_set(struct client *c, struct cmd_find_state *fs, c->prompt_string = format_expand_time(ft, msg); - c->prompt_buffer = utf8_fromcstr(tmp); + if (flags & PROMPT_INCREMENTAL) { + c->prompt_last = xstrdup(tmp); + c->prompt_buffer = utf8_fromcstr(""); + } else { + c->prompt_last = NULL; + c->prompt_buffer = utf8_fromcstr(tmp); + } c->prompt_index = utf8_strlen(c->prompt_buffer); c->prompt_inputcb = inputcb; @@ -579,11 +585,8 @@ status_prompt_set(struct client *c, struct cmd_find_state *fs, c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_REDRAWSTATUS; - if ((flags & PROMPT_INCREMENTAL) && *tmp != '\0') { - xasprintf(&cp, "=%s", tmp); - c->prompt_inputcb(c, c->prompt_data, cp, 0); - free(cp); - } + if (flags & PROMPT_INCREMENTAL) + c->prompt_inputcb(c, c->prompt_data, "=", 0); free(tmp); format_free(ft); @@ -599,6 +602,9 @@ status_prompt_clear(struct client *c) if (c->prompt_freecb != NULL && c->prompt_data != NULL) c->prompt_freecb(c->prompt_data); + free(c->prompt_last); + c->prompt_last = NULL; + free(c->prompt_string); c->prompt_string = NULL; @@ -1260,17 +1266,27 @@ process_key: status_prompt_clear(c); break; case '\022': /* C-r */ - if (c->prompt_flags & PROMPT_INCREMENTAL) { + if (~c->prompt_flags & PROMPT_INCREMENTAL) + break; + if (c->prompt_buffer[0].size == 0) { + prefix = '='; + free (c->prompt_buffer); + c->prompt_buffer = utf8_fromcstr(c->prompt_last); + c->prompt_index = utf8_strlen(c->prompt_buffer); + } else prefix = '-'; - goto changed; - } - break; + goto changed; case '\023': /* C-s */ - if (c->prompt_flags & PROMPT_INCREMENTAL) { + if (~c->prompt_flags & PROMPT_INCREMENTAL) + break; + if (c->prompt_buffer[0].size == 0) { + prefix = '='; + free (c->prompt_buffer); + c->prompt_buffer = utf8_fromcstr(c->prompt_last); + c->prompt_index = utf8_strlen(c->prompt_buffer); + } else prefix = '+'; - goto changed; - } - break; + goto changed; default: goto append_key; } diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index d711333da90..3b10768f3f0 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.309 2021/01/06 07:29:49 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.310 2021/01/08 08:22:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2030,6 +2030,8 @@ window_copy_cmd_search_backward_incremental(struct window_copy_cmd_state *cs) data->timeout = 0; + log_debug ("%s: %s", __func__, argument); + prefix = *argument++; if (data->searchx == -1 || data->searchy == -1) { data->searchx = data->cx; @@ -2083,6 +2085,8 @@ window_copy_cmd_search_forward_incremental(struct window_copy_cmd_state *cs) data->timeout = 0; + log_debug ("%s: %s", __func__, argument); + prefix = *argument++; if (data->searchx == -1 || data->searchy == -1) { data->searchx = data->cx; |