GNOME Bugzilla – Bug 170146
Entry inline completion inserts prefix in wrong position
Last modified: 2011-02-04 16:17:41 UTC
Turning on inline completion for a GtkEntry results in the prefix being inserted before the key. If the demo entry completion example is changed to use inline competion, typing "to" matches "total" and "totally", but the entry completes to "talto" with "lto" selected. The problem seems to be in gtkentrycompletion.c where gtk_entry_completion_real_insert_prefix() doesn't set pos before calling gtk_editable_insert_text().
Created attachment 38622 [details] [review] patch to gtk_entry_completion_real_insert_prefix()
I don't see that. For me, after turning on inline completion, typing "t" in the first example completes to "tot". This works regardless if popup completion is turned on or off. That being said, I have committed some small fixes for inline completion. Maybe you can check again ?
Still doesn't work for me with a CVS checkout done just a couple of hours ago. I tried both gtk-demo and testentrycompletion (leaving popup completion on) with the same results. How is gtk_entry_completion_real_insert_prefix() supposed to work? Variable pos is used by gtk_editable_insert_text() as the insert position before it's been set. This seems like a clear mistake. (The compiler can't detect this because only the address is passed so it doesn't know that it's used as an in/out parameter.) It could randomly work if the garbage value in pos happens to be negative. If you don't like the original patch that sets pos = key_len, you could instead simply initialize pos=-1 to insert at the end. static gboolean gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion, const gchar *prefix) { if (prefix) { gint key_len; gint prefix_len; gint pos; const gchar *key; prefix_len = g_utf8_strlen (prefix, -1); key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)); key_len = g_utf8_strlen (key, -1); if (prefix_len > key_len) { gtk_editable_insert_text (GTK_EDITABLE (completion->priv->entry), prefix + key_len, -1, &pos); gtk_editable_select_region (GTK_EDITABLE (completion->priv->entry), key_len, prefix_len); completion->priv->has_completion = TRUE; } } return TRUE; }
2005-03-17 Matthias Clasen <mclasen@redhat.com> * gtk/gtkentrycompletion.c (gtk_entry_completion_real_insert_prefix): Make inline completion insert the prefix at the right spot. (#170146, Doug Quale)