aboutsummaryrefslogtreecommitdiff
path: root/search.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-01-27 17:36:28 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-01-29 16:50:42 +0000
commit739e7d76b4b70da91c50a53026a83d382dd73bae (patch)
treec4a4cbfa1e7219a20dfc720471706eec96a6fd3d /search.c
parentsearch: refactor: add add_wchars(), make search_add_chars() use it (diff)
search: remember last searched-for string between searches
Regardless of how we exit search mode (commit or cancel), the search string is remembered. The next time we enter search mode, the last searched-for string will be used when searching for the next/prev match (ctrl+r, ctrl+s), and the search query is empty.
Diffstat (limited to 'search.c')
-rw-r--r--search.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/search.c b/search.c
index 2ef6a44f..8c5051af 100644
--- a/search.c
+++ b/search.c
@@ -94,10 +94,16 @@ search_cancel_keep_selection(struct terminal *term)
struct wl_window *win = term->window;
wayl_win_subsurface_destroy(&win->search);
- free(term->search.buf);
+ if (term->search.len > 0) {
+ free(term->search.last.buf);
+ term->search.last.buf = term->search.buf;
+ term->search.last.len = term->search.len;
+ } else
+ free(term->search.buf);
+
term->search.buf = NULL;
- term->search.len = 0;
- term->search.sz = 0;
+ term->search.len = term->search.sz = 0;
+
term->search.cursor = 0;
term->search.match = (struct coord){-1, -1};
term->search.match_len = 0;
@@ -630,7 +636,15 @@ execute_binding(struct seat *seat, struct terminal *term,
return true;
case BIND_ACTION_SEARCH_FIND_PREV:
- if (term->search.match_len > 0) {
+ if (term->search.last.buf != NULL && term->search.len == 0) {
+ add_wchars(term, term->search.last.buf, term->search.last.len);
+
+ free(term->search.last.buf);
+ term->search.last.buf = NULL;
+ term->search.last.len = 0;
+ }
+
+ else if (term->search.match_len > 0) {
int new_col = term->search.match.col - 1;
int new_row = term->search.match.row;
@@ -648,7 +662,15 @@ execute_binding(struct seat *seat, struct terminal *term,
return true;
case BIND_ACTION_SEARCH_FIND_NEXT:
- if (term->search.match_len > 0) {
+ if (term->search.last.buf != NULL && term->search.len == 0) {
+ add_wchars(term, term->search.last.buf, term->search.last.len);
+
+ free(term->search.last.buf);
+ term->search.last.buf = NULL;
+ term->search.last.len = 0;
+ }
+
+ else if (term->search.match_len > 0) {
int new_col = term->search.match.col + 1;
int new_row = term->search.match.row;