From e371b5fc710c597e175e6b7d7645b3a224a731a1 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 25 Sep 2026 01:43:56 +0200 Subject: 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. --- src/spawn.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/spawn.c') diff --git a/src/spawn.c b/src/spawn.c index a4bf381..933d8f4 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -422,10 +422,16 @@ teco_state_execute_done(teco_machine_main_t *ctx, teco_string_t str, GError **er teco_interface_ssm(SCI_GOTOPOS, teco_spawn_ctx.to, 0); } - teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0); teco_spawn_ctx.start = teco_spawn_ctx.from; g_main_loop_run(teco_spawn_ctx.mainloop); if (!teco_spawn_ctx.register_argument) { + if (teco_current_doc_must_undo()) { + undo__teco_interface_ssm(SCI_DELETERANGE, teco_spawn_ctx.to, + teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0)-teco_spawn_ctx.to); + teco_undo_interface_insert(teco_spawn_ctx.from, + teco_spawn_ctx.to - teco_spawn_ctx.from); + } + teco_interface_ssm(SCI_DELETERANGE, teco_spawn_ctx.from, teco_spawn_ctx.to - teco_spawn_ctx.from); @@ -437,7 +443,6 @@ teco_state_execute_done(teco_machine_main_t *ctx, teco_string_t str, GError **er teco_current_doc_set_dot(to); } - teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0); if (teco_spawn_ctx.register_argument) { if (teco_spawn_ctx.stdout_reader.eol_style >= 0) { @@ -446,9 +451,6 @@ teco_state_execute_done(teco_machine_main_t *ctx, teco_string_t str, GError **er teco_spawn_ctx.stdout_reader.eol_style); } } else if (teco_spawn_ctx.from != teco_spawn_ctx.to || teco_spawn_ctx.text_added) { - /* undo action has only been created if it changed anything */ - if (teco_current_doc_must_undo()) - undo__teco_interface_ssm(SCI_UNDO, 0, 0); teco_ring_dirtify(); } -- cgit v1.2.3