[devhelp] Sidebar: fix completion bug if multi-byte char in search entry



commit 76c44319440bc8e9f580990c6d49be117d25f258
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Jan 4 22:05:21 2018 +0100

    Sidebar: fix completion bug if multi-byte char in search entry
    
    The gtk_editable functions work with number of UTF-8 chars, not bytes.
    
    Tested with "The “a-signal-name”".

 src/dh-sidebar.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/src/dh-sidebar.c b/src/dh-sidebar.c
index 1d5b151..c364ffe 100644
--- a/src/dh-sidebar.c
+++ b/src/dh-sidebar.c
@@ -22,7 +22,6 @@
  */
 
 #include "dh-sidebar.h"
-#include <string.h>
 #include "dh-book.h"
 #include "dh-book-tree.h"
 #include "dh-keyword-model.h"
@@ -395,12 +394,14 @@ complete_idle_cb (gpointer user_data)
 
         g_completion_complete (priv->completion, search_text, &completed);
         if (completed != NULL) {
-                gsize length = strlen (search_text);
+                guint16 n_chars_before;
+
+                n_chars_before = gtk_entry_get_text_length (priv->entry);
 
                 gtk_entry_set_text (priv->entry, completed);
-                gtk_editable_set_position (GTK_EDITABLE (priv->entry), length);
+                gtk_editable_set_position (GTK_EDITABLE (priv->entry), n_chars_before);
                 gtk_editable_select_region (GTK_EDITABLE (priv->entry),
-                                            length, -1);
+                                            n_chars_before, -1);
                 g_free (completed);
         }
 


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