aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/glob.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/glob.c')
-rw-r--r--src/glob.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/glob.c b/src/glob.c
index cb571c4..c1efe47 100644
--- a/src/glob.c
+++ b/src/glob.c
@@ -482,6 +482,7 @@ teco_state_glob_filename_done(teco_machine_main_t *ctx, teco_string_t str, GErro
gboolean matching = FALSE;
gboolean colon_modified = teco_machine_main_eval_colon(ctx) > 0;
+ gsize added_len = 0;
teco_int_t teco_test_mode;
@@ -517,6 +518,8 @@ teco_state_glob_filename_done(teco_machine_main_t *ctx, teco_string_t str, GErro
return NULL;
}
+ sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0);
+
if (str.len > 0) {
/*
* Match pattern against provided file name
@@ -535,12 +538,10 @@ teco_state_glob_filename_done(teco_machine_main_t *ctx, teco_string_t str, GErro
gsize len = strlen(filename);
filename[len] = '\n';
- sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0);
teco_undo_int(teco_ranges[0].from) = teco_current_doc_get_dot();
- teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0);
teco_interface_ssm(SCI_ADDTEXT, len+1, (sptr_t)filename);
- teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0);
+ added_len += len+1;
teco_int_t to = teco_interface_bytes2glyphs_rel(teco_ranges[0].from, pos, len + 1);
teco_undo_int(teco_ranges[0].to) = to;
@@ -568,12 +569,9 @@ teco_state_glob_filename_done(teco_machine_main_t *ctx, teco_string_t str, GErro
g_autoptr(teco_globber_t) globber;
globber = teco_globber_new(pattern_str.data, file_flags);
- sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0);
gsize total_len = 0;
teco_undo_int(teco_ranges[0].from) = teco_current_doc_get_dot();
- teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0);
-
gchar *globbed_filename;
while ((globbed_filename = teco_globber_next(globber))) {
gsize len = strlen(globbed_filename);
@@ -585,13 +583,12 @@ teco_state_glob_filename_done(teco_machine_main_t *ctx, teco_string_t str, GErro
*/
globbed_filename[len] = '\n';
teco_interface_ssm(SCI_ADDTEXT, len+1, (sptr_t)globbed_filename);
+ added_len += len+1;
g_free(globbed_filename);
matching = TRUE;
}
- teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0);
-
teco_int_t to = teco_interface_bytes2glyphs_rel(teco_ranges[0].from, pos, total_len);
teco_undo_int(teco_ranges[0].to) = to;
teco_undo_guint(teco_ranges_count) = 1;
@@ -600,11 +597,11 @@ teco_state_glob_filename_done(teco_machine_main_t *ctx, teco_string_t str, GErro
if (colon_modified) {
teco_expressions_push(teco_bool(matching));
- } else if (matching) {
+ } else if (added_len) {
/* text has been inserted */
teco_ring_dirtify();
if (teco_current_doc_must_undo())
- undo__teco_interface_ssm(SCI_UNDO, 0, 0);
+ undo__teco_interface_ssm(SCI_DELETERANGE, pos, added_len);
}
if (!glob_reg->vtable->set_integer(glob_reg, teco_bool(matching), error))