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/search.c | |
| parent | 207af96f4eb3220534ea06c2e107517372246544 (diff) | |
instead of relying on Scintilla undo actions, use SciTECO undo tokens exclusively
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/search.c')
| -rw-r--r-- | src/search.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/search.c b/src/search.c index 2b2a696..31a551e 100644 --- a/src/search.c +++ b/src/search.c @@ -1353,7 +1353,6 @@ teco_state_search_kill_done(teco_machine_main_t *ctx, teco_string_t str, GError sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); - teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0); if (teco_search_parameters.pos < pos) { /* kill forwards */ sptr_t anchor = teco_interface_ssm(SCI_GETANCHOR, 0, 0); @@ -1361,17 +1360,13 @@ teco_state_search_kill_done(teco_machine_main_t *ctx, teco_string_t str, GError teco_interface_bytes2glyphs_absdot(teco_search_parameters.pos); if (teco_current_doc_must_undo()) - undo__teco_interface_ssm(SCI_GOTOPOS, pos, 0); + teco_undo_interface_insert(teco_search_parameters.pos, + anchor - teco_search_parameters.pos); teco_interface_ssm(SCI_GOTOPOS, anchor, 0); teco_interface_ssm(SCI_DELETERANGE, teco_search_parameters.pos, anchor - teco_search_parameters.pos); - /* NOTE: An undo action is not always created. */ - if (teco_current_doc_must_undo() && - teco_search_parameters.pos != anchor) - undo__teco_interface_ssm(SCI_UNDO, 0, 0); - /* fix up ranges (^Y) */ for (guint i = 0; i < teco_ranges_count; i++) { teco_ranges[i].from -= len_glyphs; @@ -1384,14 +1379,10 @@ teco_state_search_kill_done(teco_machine_main_t *ctx, teco_string_t str, GError /* kill backwards */ teco_current_doc_set_dot(teco_interface_bytes2glyphs_absdot(pos)); + if (teco_current_doc_must_undo()) + teco_undo_interface_insert(pos, teco_search_parameters.pos - pos); teco_interface_ssm(SCI_DELETERANGE, pos, teco_search_parameters.pos - pos); - - /* NOTE: An undo action is not always created. */ - if (teco_current_doc_must_undo() && - teco_search_parameters.pos != pos) - undo__teco_interface_ssm(SCI_UNDO, 0, 0); } - teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0); teco_ring_dirtify(); return &teco_state_start; @@ -1438,13 +1429,13 @@ teco_state_search_delete_done(teco_machine_main_t *ctx, teco_string_t str, GErro sptr_t anchor = teco_interface_ssm(SCI_GETANCHOR, 0, 0); teco_current_doc_set_dot(teco_interface_bytes2glyphs_absdot(anchor)); - teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0); + if (teco_current_doc_must_undo()) { + gsize start = teco_interface_ssm(SCI_GETSELECTIONSTART, 0, 0); + teco_undo_interface_insert(start, teco_interface_ssm(SCI_GETSELECTIONEND, 0, 0) - start); + } + teco_interface_ssm(SCI_REPLACESEL, 0, (sptr_t)""); - teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0); teco_ring_dirtify(); - - if (teco_current_doc_must_undo()) - undo__teco_interface_ssm(SCI_UNDO, 0, 0); } return &teco_state_start; |
