aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-05-10 23:47:26 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-05-10 23:47:26 +0200
commitc011363117c18d9332c42d4e5ec7f6ba3f932ec3 (patch)
tree347bdc683457ea51ac78ae7aedcc7b78d013aefb
parentdb314a6b421a0bc4a8d58605e9bd18f7aa2067cd (diff)
allow CTRL+C interrupting forward and background searchesHEADmaster
* 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.
-rw-r--r--src/search.c12
1 files changed, 12 insertions, 0 deletions
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);
}