From 3f6572c5b46254002cb1b3fd1001bc28ecc2bb10 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 8 Dec 2024 16:41:34 +0300 Subject: [PATCH] fixed rubbing out file open with glob patterns * This would crash if opened more than one file, e.g. EB*.c$. The reason is that teco_current_doc_undo_edit() must be called before every teco_ring_edit(). * Unfortunately, this is not reproduceable with sciteco --no-profile --fake-cmdline '@EB"foo*.txt"{HK}' since the crashes actually happen when printing messages in interactive mode. That's why no test case has been added. --- src/ring.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ring.c b/src/ring.c index d6fadda..8ce6948 100644 --- a/src/ring.c +++ b/src/ring.c @@ -441,9 +441,6 @@ teco_state_edit_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE return &teco_state_start; } - if (!teco_current_doc_undo_edit(error)) - return NULL; - g_autofree gchar *filename = teco_file_expand_path(str->data); if (teco_globber_is_pattern(filename)) { g_auto(teco_globber_t) globber; @@ -451,13 +448,15 @@ teco_state_edit_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE gchar *globbed_filename; while ((globbed_filename = teco_globber_next(&globber))) { - gboolean rc = teco_ring_edit(globbed_filename, error); + gboolean rc = teco_current_doc_undo_edit(error) && + teco_ring_edit(globbed_filename, error); g_free(globbed_filename); if (!rc) return NULL; } } else { - if (!teco_ring_edit_by_name(*filename ? filename : NULL, error)) + if (!teco_current_doc_undo_edit(error) || + !teco_ring_edit_by_name(*filename ? filename : NULL, error)) return NULL; }