summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-07-16 11:04:21 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-07-16 11:04:21 +0000
commit6ff85d287a50bc33ccb73d10ad7acc1255ca2bed (patch)
treec5f6c5627081f8c938e613e07fa97580f18ff570
parentb70b058b66fcbfbd453ec5a705db062c2dd5d2c1 (diff)
parent5d02a8f5dbe285a6ff48884520a17c348bcc6774 (diff)
downloadgtk+-6ff85d287a50bc33ccb73d10ad7acc1255ca2bed.tar.gz
Merge branch 'wip/chergert/fix-texthistory-insert' into 'master'
texthistory: fix calculation of n_chars See merge request GNOME/gtk!3756
-rw-r--r--gtk/gtktexthistory.c9
-rw-r--r--testsuite/gtk/texthistory.c27
2 files changed, 31 insertions, 5 deletions
diff --git a/gtk/gtktexthistory.c b/gtk/gtktexthistory.c
index 1d97ff31a7..61ccc33f08 100644
--- a/gtk/gtktexthistory.c
+++ b/gtk/gtktexthistory.c
@@ -989,6 +989,7 @@ gtk_text_history_text_inserted (GtkTextHistory *self,
int len)
{
Action *action;
+ guint n_chars;
g_return_if_fail (GTK_IS_TEXT_HISTORY (self));
@@ -998,14 +999,12 @@ gtk_text_history_text_inserted (GtkTextHistory *self,
if (len < 0)
len = strlen (text);
+ n_chars = g_utf8_strlen (text, len);
action = action_new (ACTION_KIND_INSERT);
action->u.insert.begin = position;
- action->u.insert.end = position + g_utf8_strlen (text, len);
- istring_set (&action->u.insert.istr,
- text,
- len,
- action->u.insert.end);
+ action->u.insert.end = position + n_chars;
+ istring_set (&action->u.insert.istr, text, len, n_chars);
gtk_text_history_push (self, action);
}
diff --git a/testsuite/gtk/texthistory.c b/testsuite/gtk/texthistory.c
index f9fe45ceb2..c64c803083 100644
--- a/testsuite/gtk/texthistory.c
+++ b/testsuite/gtk/texthistory.c
@@ -578,6 +578,32 @@ test13 (void)
run_test (commands, G_N_ELEMENTS (commands), 3);
}
+static void
+test14 (void)
+{
+ char *fill = g_strnfill (1024, 'x');
+ char *fill_after = g_strnfill (1025, 'x');
+ char *fill_after_2 = g_strdup_printf ("%s word", fill_after);
+ const Command commands[] = {
+ { BEGIN_USER, -1, -1, NULL, NULL, UNSET, UNSET, UNSET },
+ { INSERT, 0, -1, fill, fill, UNSET, UNSET, UNSET },
+ { END_USER, -1, -1, NULL, NULL, SET, UNSET, UNSET },
+ { BEGIN_USER, -1, -1, NULL, NULL, UNSET, UNSET, UNSET },
+ { INSERT, 0, -1, "x", fill_after, UNSET, UNSET, UNSET },
+ { END_USER, -1, -1, NULL, NULL, SET, UNSET, UNSET },
+ { BEGIN_USER, -1, -1, NULL, NULL, UNSET, UNSET, UNSET },
+ { INSERT_SEQ, strlen(fill_after), -1, " word", fill_after_2, UNSET, UNSET, UNSET },
+ { END_USER, -1, -1, NULL, NULL, SET, UNSET, UNSET },
+ { UNDO, -1, -1, NULL, fill_after, SET, SET, UNSET },
+ { UNDO, -1, -1, NULL, fill, SET, SET, UNSET },
+ { UNDO, -1, -1, NULL, "", UNSET, SET, UNSET },
+ };
+
+ run_test (commands, G_N_ELEMENTS (commands), 0);
+
+ g_free (fill);
+}
+
int
main (int argc,
char *argv[])
@@ -597,6 +623,7 @@ main (int argc,
g_test_add_func ("/Gtk/TextHistory/test11", test11);
g_test_add_func ("/Gtk/TextHistory/test12", test12);
g_test_add_func ("/Gtk/TextHistory/test13", test13);
+ g_test_add_func ("/Gtk/TextHistory/test14", test14);
return g_test_run ();
}