diff options
Diffstat (limited to 'src/search.c')
| -rw-r--r-- | src/search.c | 28 |
1 files changed, 24 insertions, 4 deletions
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 ); |
