forked from AuroraMiddleware/gtk
Merge branch 'wip/chergert/fix-texthistory-insert' into 'master'
texthistory: fix calculation of n_chars See merge request GNOME/gtk!3756
This commit is contained in:
commit
6ff85d287a
@ -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);
|
||||
}
|
||||
|
@ -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 ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user