diff options
| -rw-r--r-- | src/search.c | 28 | ||||
| -rw-r--r-- | tests/testsuite.at | 2 |
2 files changed, 26 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 ); diff --git a/tests/testsuite.at b/tests/testsuite.at index ec6b034..a360840 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -291,6 +291,8 @@ AT_SETUP([Search and insertion ranges]) TE_CHECK([[@I/XXYYZZ/^SC ."N(0/0)' C @S/YY/ HK ^YU1U0 Q0-2"N(0/0)' Q1-4"N(0/0)']], 0, ignore, ignore) TE_CHECK([[@I/XXYYZZ/J @S/XX^E[^EMY]/ 1^YXa :Qa-2"N(0/0)']], 0, ignore, ignore) TE_CHECK([[@I/XXYYZZ/J @FD/^EMZ/ ^S+2"N(0/0)']], 0, ignore, ignore) +TE_CHECK([[@I/ABCDEF/J @^U-/1234/ @FR/ABC// ^S+4"N(0/0)']], 0, ignore, ignore) +TE_CHECK([[@I/ABCDEF/J @FS/ABC/1234/ ^S+4"N(0/0)']], 0, ignore, ignore) TE_CHECK([[@^Ua/XYZ/ Ga ^S+3"N(0/0)']], 0, ignore, ignore) # NOTE: EN currently inserts another trailing linefeed. TE_CHECK([[@EN/*/XYZ/ ^S+4"N(0/0)']], 0, ignore, ignore) |
