aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-27 19:51:10 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-28 04:32:12 +0300
commit427092d2c8ee11b4a56eb50dbf68861f10f2a81f (patch)
tree87b6be1df9aaa7a69a615f759f347562a8bdaf9b
parent5a6862bba8eed7fc1f74592b88f677e22ed86f25 (diff)
downloadsciteco-427092d2c8ee11b4a56eb50dbf68861f10f2a81f.tar.gz
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.
-rw-r--r--src/qreg-commands.c9
-rw-r--r--src/qreg.c45
-rw-r--r--src/qreg.h3
-rw-r--r--src/spawn.c3
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,
@@ -671,12 +686,6 @@ teco_qreg_workingdir_append_string(teco_qreg_t *qreg, const gchar *str, gsize le
}
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
);
@@ -779,12 +787,6 @@ teco_qreg_clipboard_append_string(teco_qreg_t *qreg, const gchar *str, gsize len
}
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 {