From 427092d2c8ee11b4a56eb50dbf68861f10f2a81f Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 27 Oct 2024 19:51:10 +0300 Subject: fixed rubbing out <:Xq>, <:^Uq> and other append-to-register operations * This was a regression introduced in 41ab5cf0289dab60ac1ddc97cf9680ee2468ea6c, which changed the semantics of teco_doc_undo_set_string(). * Removed undo_append_string() Q-Reg virtual method. append_string() now does its own undo token emission, so that we can defer the teco_doc_undo_edit() after the point that the document was initialized. This is important, so that we can configure the default encoding on new registers. --- src/qreg-commands.c | 9 +++------ src/qreg.c | 45 +++++++++++++++++++++++---------------------- src/qreg.h | 3 ++- src/spawn.c | 3 +-- 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/qreg-commands.c b/src/qreg-commands.c index 5b80d15..6fb68f2 100644 --- a/src/qreg-commands.c +++ b/src/qreg-commands.c @@ -408,8 +408,7 @@ teco_state_setqregstring_nobuilding_done(teco_machine_main_t *ctx, if (colon_modified) { /* append to register */ - if (!qreg->vtable->undo_append_string(qreg, error) || - !qreg->vtable->append_string(qreg, buffer, len, error)) + if (!qreg->vtable->append_string(qreg, buffer, len, error)) return NULL; } else { /* set register */ @@ -422,8 +421,7 @@ teco_state_setqregstring_nobuilding_done(teco_machine_main_t *ctx, if (args > 0 || colon_modified) { /* append to register */ - if (!qreg->vtable->undo_append_string(qreg, error) || - !qreg->vtable->append_string(qreg, str->data, str->len, error)) + if (!qreg->vtable->append_string(qreg, str->data, str->len, error)) return NULL; } else { /* set register */ @@ -790,8 +788,7 @@ teco_state_copytoqreg_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg, teco_interface_ssm(SCI_GETTEXTRANGEFULL, 0, (sptr_t)&range); if (teco_machine_main_eval_colon(ctx)) { - if (!qreg->vtable->undo_append_string(qreg, error) || - !qreg->vtable->append_string(qreg, str, len, error)) + if (!qreg->vtable->append_string(qreg, str, len, error)) return NULL; } else { guint cp = teco_interface_get_codepage(); diff --git a/src/qreg.c b/src/qreg.c index a0e5415..487a725 100644 --- a/src/qreg.c +++ b/src/qreg.c @@ -183,6 +183,20 @@ teco_qreg_plain_append_string(teco_qreg_t *qreg, const gchar *str, gsize len, GE if (!len) return TRUE; + if (qreg->must_undo) { // FIXME + /* + * Necessary, so that upon rubout the + * string's parameters are restored. + */ + teco_doc_update(&qreg->string, teco_qreg_view); + + if (teco_qreg_current && teco_qreg_current->must_undo) // FIXME + teco_doc_undo_edit(&teco_qreg_current->string); + + teco_doc_undo_reset(&qreg->string); + undo__teco_view_ssm(teco_qreg_view, SCI_UNDO, 0, 0); + } + if (teco_qreg_current) teco_doc_update(&teco_qreg_current->string, teco_qreg_view); @@ -194,6 +208,15 @@ teco_qreg_plain_append_string(teco_qreg_t *qreg, const gchar *str, gsize len, GE if (teco_qreg_current) teco_doc_edit(&teco_qreg_current->string, 0); + + /* + * Make sure these undo tokens are only generated now, + * so that teco_doc_edit() always initializes the document and + * the default codepage. + */ + if (qreg->must_undo) // FIXME + teco_doc_undo_edit(&qreg->string); + return TRUE; } @@ -354,7 +377,6 @@ teco_qreg_plain_save(teco_qreg_t *qreg, const gchar *filename, GError **error) .set_string = teco_qreg_plain_set_string, \ .undo_set_string = teco_qreg_plain_undo_set_string, \ .append_string = teco_qreg_plain_append_string, \ - .undo_append_string = teco_qreg_plain_undo_set_string, \ .get_string = teco_qreg_plain_get_string, \ .get_character = teco_qreg_plain_get_character, \ .get_length = teco_qreg_plain_get_length, \ @@ -567,12 +589,6 @@ teco_qreg_bufferinfo_append_string(teco_qreg_t *qreg, const gchar *str, gsize le return FALSE; } -static gboolean -teco_qreg_bufferinfo_undo_append_string(teco_qreg_t *qreg, GError **error) -{ - return TRUE; -} - /* * NOTE: The `string` component is currently unused on the "*" register. */ @@ -609,7 +625,6 @@ teco_qreg_bufferinfo_new(void) .set_string = teco_qreg_bufferinfo_set_string, .undo_set_string = teco_qreg_bufferinfo_undo_set_string, .append_string = teco_qreg_bufferinfo_append_string, - .undo_append_string = teco_qreg_bufferinfo_undo_append_string, .get_string = teco_qreg_bufferinfo_get_string, /* * As teco_qreg_bufferinfo_set_string() is not implemented, @@ -670,12 +685,6 @@ teco_qreg_workingdir_append_string(teco_qreg_t *qreg, const gchar *str, gsize le return FALSE; } -static gboolean -teco_qreg_workingdir_undo_append_string(teco_qreg_t *qreg, GError **error) -{ - return TRUE; -} - static gboolean teco_qreg_workingdir_get_string(teco_qreg_t *qreg, gchar **str, gsize *len, guint *codepage, GError **error) @@ -709,7 +718,6 @@ teco_qreg_workingdir_new(void) .set_string = teco_qreg_workingdir_set_string, .undo_set_string = teco_qreg_workingdir_undo_set_string, .append_string = teco_qreg_workingdir_append_string, - .undo_append_string = teco_qreg_workingdir_undo_append_string, .get_string = teco_qreg_workingdir_get_string ); @@ -778,12 +786,6 @@ teco_qreg_clipboard_append_string(teco_qreg_t *qreg, const gchar *str, gsize len return FALSE; } -static gboolean -teco_qreg_clipboard_undo_append_string(teco_qreg_t *qreg, GError **error) -{ - return TRUE; -} - static gboolean teco_qreg_clipboard_undo_set_string(teco_qreg_t *qreg, GError **error) { @@ -878,7 +880,6 @@ teco_qreg_clipboard_new(const gchar *name) .set_string = teco_qreg_clipboard_set_string, .undo_set_string = teco_qreg_clipboard_undo_set_string, .append_string = teco_qreg_clipboard_append_string, - .undo_append_string = teco_qreg_clipboard_undo_append_string, .get_string = teco_qreg_clipboard_get_string, .load = teco_qreg_clipboard_load ); diff --git a/src/qreg.h b/src/qreg.h index f5866e7..59cf2cc 100644 --- a/src/qreg.h +++ b/src/qreg.h @@ -52,8 +52,9 @@ typedef const struct { gboolean (*set_string)(teco_qreg_t *qreg, const gchar *str, gsize len, guint codepage, GError **error); gboolean (*undo_set_string)(teco_qreg_t *qreg, GError **error); + + /* does not need an explicit undo-call */ gboolean (*append_string)(teco_qreg_t *qreg, const gchar *str, gsize len, GError **error); - gboolean (*undo_append_string)(teco_qreg_t *qreg, GError **error); gboolean (*get_string)(teco_qreg_t *qreg, gchar **str, gsize *len, guint *codepage, GError **error); diff --git a/src/spawn.c b/src/spawn.c index 06fdf95..7a5736c 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -761,8 +761,7 @@ teco_spawn_stdout_watch_cb(GIOChannel *chan, GIOCondition condition, gpointer da if (qreg) { if (teco_spawn_ctx.text_added) { - if (!qreg->vtable->undo_append_string(qreg, &teco_spawn_ctx.error) || - !qreg->vtable->append_string(qreg, buffer.data, buffer.len, + if (!qreg->vtable->append_string(qreg, buffer.data, buffer.len, &teco_spawn_ctx.error)) goto error; } else { -- cgit v1.2.3