mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-23 05:33:57 -04:00
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.
This commit is contained in:
parent
22266e384b
commit
739e7d76b4
3 changed files with 33 additions and 5 deletions
32
search.c
32
search.c
|
|
@ -94,10 +94,16 @@ search_cancel_keep_selection(struct terminal *term)
|
||||||
struct wl_window *win = term->window;
|
struct wl_window *win = term->window;
|
||||||
wayl_win_subsurface_destroy(&win->search);
|
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.buf = NULL;
|
||||||
term->search.len = 0;
|
term->search.len = term->search.sz = 0;
|
||||||
term->search.sz = 0;
|
|
||||||
term->search.cursor = 0;
|
term->search.cursor = 0;
|
||||||
term->search.match = (struct coord){-1, -1};
|
term->search.match = (struct coord){-1, -1};
|
||||||
term->search.match_len = 0;
|
term->search.match_len = 0;
|
||||||
|
|
@ -630,7 +636,15 @@ execute_binding(struct seat *seat, struct terminal *term,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case BIND_ACTION_SEARCH_FIND_PREV:
|
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_col = term->search.match.col - 1;
|
||||||
int new_row = term->search.match.row;
|
int new_row = term->search.match.row;
|
||||||
|
|
||||||
|
|
@ -648,7 +662,15 @@ execute_binding(struct seat *seat, struct terminal *term,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case BIND_ACTION_SEARCH_FIND_NEXT:
|
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_col = term->search.match.col + 1;
|
||||||
int new_row = term->search.match.row;
|
int new_row = term->search.match.row;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1638,6 +1638,7 @@ term_destroy(struct terminal *term)
|
||||||
&term->custom_glyphs.legacy, GLYPH_LEGACY_COUNT);
|
&term->custom_glyphs.legacy, GLYPH_LEGACY_COUNT);
|
||||||
|
|
||||||
free(term->search.buf);
|
free(term->search.buf);
|
||||||
|
free(term->search.last.buf);
|
||||||
|
|
||||||
if (term->render.workers.threads != NULL) {
|
if (term->render.workers.threads != NULL) {
|
||||||
for (size_t i = 0; i < term->render.workers.count; i++) {
|
for (size_t i = 0; i < term->render.workers.count; i++) {
|
||||||
|
|
|
||||||
|
|
@ -514,6 +514,11 @@ struct terminal {
|
||||||
bool view_followed_offset;
|
bool view_followed_offset;
|
||||||
struct coord match;
|
struct coord match;
|
||||||
size_t match_len;
|
size_t match_len;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
wchar_t *buf;
|
||||||
|
size_t len;
|
||||||
|
} last;
|
||||||
} search;
|
} search;
|
||||||
|
|
||||||
struct wayland *wl;
|
struct wayland *wl;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue