From 44166f53d5923be4685a69b85166ada40dc1cc10 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 25 Dec 2025 22:55:32 +0100 Subject: fixed ^S/^Y for search-replacement commands It was returning the range of the search, but not of the inserted text. Since the searched text is deleted, the range of the insertion is more useful. It's also what was documented and what DEC TECO does. --- src/search.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/search.c b/src/search.c index 5ef2179..0875a9a 100644 --- a/src/search.c +++ b/src/search.c @@ -1205,9 +1205,24 @@ TECO_DEFINE_STATE_SEARCH(teco_state_search_delete); static gboolean teco_state_replace_insert_initial(teco_machine_main_t *ctx, GError **error) { - if (ctx->flags.mode == TECO_MODE_NORMAL) - teco_machine_stringbuilding_set_codepage(&ctx->expectstring.machine, - teco_interface_get_codepage()); + if (ctx->flags.mode > TECO_MODE_NORMAL) + return TRUE; + + /* + * Overwrites teco_ranges set by the preceding search. + * FIXME: Wastes undo tokens in teco_do_search(). + * Perhaps make this configurable in the state. + */ + sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + teco_undo_int(teco_ranges[0].from) = teco_interface_bytes2glyphs(pos); + teco_undo_guint(teco_ranges_count) = 1; + + /* + * Current document's encoding determines the behaviour of + * string building constructs. + */ + teco_machine_stringbuilding_set_codepage(&ctx->expectstring.machine, + teco_interface_get_codepage()); return TRUE; } @@ -1277,6 +1292,9 @@ TECO_DEFINE_STATE_SEARCH(teco_state_replace, * FIXME: TECO_DEFINE_STATE_INSERT() already defines a done_cb(), * so we had to name this differently. * Perhaps it simply shouldn't define it. + * Even better, we should perhaps avoid generating "required" callback + * names (e.g. in TECO_DEFINE_STATE_EXPECTSTRING()) as it does more harm + * than it helps and only spreads confusion. */ static teco_state_t * teco_state_replace_default_insert_done_overwrite(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) @@ -1300,6 +1318,8 @@ teco_state_replace_default_insert_done_overwrite(teco_machine_main_t *ctx, const return NULL; } + sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + teco_undo_int(teco_ranges[0].to) = teco_interface_bytes2glyphs(pos); return &teco_state_start; } @@ -1307,7 +1327,7 @@ teco_state_replace_default_insert_done_overwrite(teco_machine_main_t *ctx, const * FIXME: Could be static */ TECO_DEFINE_STATE_INSERT(teco_state_replace_default_insert, - .initial_cb = NULL, + .initial_cb = (teco_state_initial_cb_t)teco_state_replace_insert_initial, .expectstring.done_cb = teco_state_replace_default_insert_done_overwrite ); -- cgit v1.2.3