diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-09-25 01:43:56 +0200 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-09-25 01:43:56 +0200 |
| commit | e371b5fc710c597e175e6b7d7645b3a224a731a1 (patch) | |
| tree | 3861fa4949adfd1c95a06ae0b7dd41c4167a3b7a /src/glob.c | |
| parent | 207af96f4eb3220534ea06c2e107517372246544 (diff) | |
instead of relying on Scintilla undo actions, use SciTECO undo tokens exclusivelyHEADmaster-fmsbw-cimaster
Previously we were using both Scintilla undo actions and our own undo tokens
and both had to be coordinated via `undo__teco_interface_ssm(SCI_UNDO, 0, 0)`.
This was error prone since we have to predict when an undo action is actually
generated. Furthermore, you had to update SCI_SETUNDOCOLLECTION on all buffers
and the Q-Reg view whenever switching to and from interactive mode.
Also, this probably wasted memory for the doubled undo bookkeeping.
Now, we always set SCI_SETUNDOCOLLECTION(FALSE), even in interactive mode.
teco_undo_view_insert() was introduced to undo text deletions.
While this saves almost no lines of code, it's just a clearer and simpler
architecture.
Diffstat (limited to 'src/glob.c')
| -rw-r--r-- | src/glob.c | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -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)) |
