From b96c5e3687d36cea7b575a7e151326f1b82824d2 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 8 Jan 2021 08:22:10 +0000 Subject: [PATCH] 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. --- status.c | 46 +++++++++++++++++++++++++++++++--------------- window-copy.c | 4 ++++ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/status.c b/status.c index 668c0a3b..82107c58 100644 --- a/status.c +++ b/status.c @@ -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/window-copy.c b/window-copy.c index 4c81cb1f..bfa94aed 100644 --- a/window-copy.c +++ b/window-copy.c @@ -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;