From c011363117c18d9332c42d4e5ec7f6ba3f932ec3 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 10 May 2026 23:47:26 +0200 Subject: allow CTRL+C interrupting forward and background searches * You can provoke hangs in forward searches when opening large files: `100000S^X$` This cannot be sped up, but must be interruptible. * With backwards searches it is even easier to provoke. Go to the end of a large file and perform any backwards search, even `-S$`. Since we must always search from the beginning of the document, you will always produce all matches over the entire document. There might be ways to speed up backwards searches, but they must be interruptible anyway. * Perhaps we can extend back the search range in chunks of 1-4kb until we produce at least `-count` matches. --- src/search.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/search.c b/src/search.c index 856d079..89bf688 100644 --- a/src/search.c +++ b/src/search.c @@ -603,6 +603,11 @@ teco_do_search(GRegex *re, gsize from, gsize to, gint *count, GError **error) g_propagate_error(error, tmp_error); return FALSE; } + + if (G_UNLIKELY(teco_interface_is_interrupted())) { + teco_error_interrupted_set(error); + return FALSE; + } } if (!*count) @@ -659,6 +664,13 @@ teco_do_search(GRegex *re, gsize from, gsize to, gint *count, GError **error) return FALSE; } + if (G_UNLIKELY(teco_interface_is_interrupted())) { + teco_error_interrupted_set(error); + for (int i = 0; i < matched_num; i++) + g_free(matched[i].ranges); + return FALSE; + } + i = ++matched_total % -(*count); } -- cgit v1.2.3