[gtk/wip/chergert/fix-texthistory-insert] texthistory: fix calculation of n_chars




commit 450076a9f86497cdc6fcd4fce1d4b5d4a7da4dd8
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jul 15 19:19:57 2021 -0700

    texthistory: fix calculation of n_chars
    
    This should be the number of characters, not the end position. This fixes
    an issue where we wouldn't coalesce insert actions together.

 gtk/gtktexthistory.c | 9 ++++-----
 1 file changed, 4 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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]