search: reset match state when selection is cancelled

While we’re in scrollback search mode, the selection may be
cancelled (for example, if the application is scrolling out the
selected text). Trying to e.g. extend the search selection after this
has happened triggered a crash.

This fixes it by simply resetting the search match state when the
selection is cancelled.

Closes #644
This commit is contained in:
Daniel Eklöf 2021-07-22 17:53:29 +02:00
parent a987b1bd99
commit 251545203b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 15 additions and 0 deletions

View file

@ -39,6 +39,9 @@
* Rendering into the right margin area with `tweak.overflowing-glyphs`
enabled.
* PGO builds with clang (https://codeberg.org/dnkl/foot/issues/642).
* Crash in scrollback search mode when selection has been canceled due
to terminal content updates
(https://codeberg.org/dnkl/foot/issues/644).
### Security

View file

@ -155,6 +155,13 @@ search_cancel(struct terminal *term)
selection_cancel(term);
}
void
search_selection_cancelled(struct terminal *term)
{
term->search.match = (struct coord){-1, -1};
term->search.match_len = 0;
}
static void
search_update_selection(struct terminal *term,
int start_row, int start_col,

View file

@ -11,3 +11,5 @@ void search_input(
const xkb_keysym_t *raw_syms, size_t raw_count,
uint32_t serial);
void search_add_chars(struct terminal *term, const char *text, size_t len);
void search_selection_cancelled(struct terminal *term);

View file

@ -21,6 +21,7 @@
#include "grid.h"
#include "misc.h"
#include "render.h"
#include "search.h"
#include "uri.h"
#include "util.h"
#include "vt.h"
@ -1058,6 +1059,8 @@ selection_cancel(struct terminal *term)
term->selection.pivot.end = (struct coord){-1, -1};
term->selection.direction = SELECTION_UNDIR;
term->selection.ongoing = false;
search_selection_cancelled(term);
}
bool