aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2022-06-21 03:07:16 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2022-06-21 03:27:54 +0200
commitd6126b318a55b06a1fde717e92c47bb9b3696708 (patch)
tree9eaa163b1c8d790403c55772b9fbf1962cb69046
parent2b93e15597f82c5bf324c317b3e9d6462dde770b (diff)
downloadsciteco-d6126b318a55b06a1fde717e92c47bb9b3696708.tar.gz
fixed rubout of certain constructs like Ifoo$FRX$$
* avoid emitting SCI_UNDO undo tokens if the Scintilla undo action would actually be empty
-rw-r--r--src/core-commands.c13
-rw-r--r--src/search.c6
-rw-r--r--src/spawn.c2
3 files changed, 17 insertions, 4 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index 99b37bf..1c52e5a 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -194,6 +194,8 @@ teco_state_start_backslash(teco_machine_main_t *ctx, GError **error)
gchar buffer[TECO_EXPRESSIONS_FORMAT_LEN];
gchar *str = teco_expressions_format(buffer, value);
+ g_assert(*str != '\0');
+
teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0);
teco_interface_ssm(SCI_ADDTEXT, strlen(str), (sptr_t)str);
teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0);
@@ -460,7 +462,10 @@ teco_state_start_cmdline_push(teco_machine_main_t *ctx, GError **error)
teco_interface_ssm(SCI_ADDTEXT, teco_cmdline.pc, (sptr_t)teco_cmdline.str.data);
teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0);
- /* must always support undo on global register */
+ /*
+ * Must always support undo on global register.
+ * A undo action should always have been generated.
+ */
undo__teco_interface_ssm(SCI_UNDO, 0, 0);
}
@@ -770,6 +775,7 @@ teco_delete_words(teco_int_t n)
}
return TECO_FAILURE;
}
+ g_assert(size != teco_interface_ssm(SCI_GETLENGTH, 0, 0));
undo__teco_interface_ssm(SCI_SETEMPTYSELECTION, pos, 0);
if (teco_current_doc_must_undo())
@@ -921,6 +927,9 @@ teco_state_start_kill(teco_machine_main_t *ctx, const gchar *cmd, gboolean by_li
undo__teco_interface_ssm(SCI_UNDO, 0, 0);
}
+ /*
+ * Should always generate an undo action.
+ */
teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0);
teco_interface_ssm(SCI_DELETERANGE, from, len);
teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0);
@@ -2381,6 +2390,8 @@ gboolean
teco_state_insert_process(teco_machine_main_t *ctx, const teco_string_t *str,
gsize new_chars, GError **error)
{
+ g_assert(new_chars > 0);
+
teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0);
teco_interface_ssm(SCI_ADDTEXT, new_chars,
(sptr_t)(str->data + str->len - new_chars));
diff --git a/src/search.c b/src/search.c
index 219ddb2..80b8ea2 100644
--- a/src/search.c
+++ b/src/search.c
@@ -914,7 +914,9 @@ teco_state_search_kill_done(teco_machine_main_t *ctx, const teco_string_t *str,
teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0);
teco_ring_dirtify();
- if (teco_current_doc_must_undo())
+ /* NOTE: An undo action is not always created. */
+ if (teco_current_doc_must_undo() &&
+ teco_search_parameters.dot != dot)
undo__teco_interface_ssm(SCI_UNDO, 0, 0);
return &teco_state_start;
@@ -1065,7 +1067,7 @@ teco_state_replace_default_insert_done_overwrite(teco_machine_main_t *ctx, const
} else {
g_auto(teco_string_t) replace_str = {NULL, 0};
if (!replace_reg->vtable->get_string(replace_reg, &replace_str.data, &replace_str.len, error) ||
- !teco_state_insert_process(ctx, &replace_str, replace_str.len, error))
+ (replace_str.len > 0 && !teco_state_insert_process(ctx, &replace_str, replace_str.len, error)))
return NULL;
}
diff --git a/src/spawn.c b/src/spawn.c
index 46454ff..abaaa0e 100644
--- a/src/spawn.c
+++ b/src/spawn.c
@@ -316,7 +316,7 @@ teco_state_execute_done(teco_machine_main_t *ctx, const teco_string_t *str, GErr
teco_spawn_ctx.stdout_reader.eol_style);
}
} else if (teco_spawn_ctx.from != teco_spawn_ctx.to || teco_spawn_ctx.text_added) {
- /* undo action is only effective if it changed anything */
+ /* 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();