After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 170146 - Entry inline completion inserts prefix in wrong position
Entry inline completion inserts prefix in wrong position
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.6.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2005-03-13 07:45 UTC by Doug Quale
Modified: 2011-02-04 16:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to gtk_entry_completion_real_insert_prefix() (357 bytes, patch)
2005-03-13 07:47 UTC, Doug Quale
none Details | Review

Description Doug Quale 2005-03-13 07:45:00 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().
Comment 1 Doug Quale 2005-03-13 07:47:31 UTC
Created attachment 38622 [details] [review]
patch to gtk_entry_completion_real_insert_prefix()
Comment 2 Matthias Clasen 2005-03-15 15:01:12 UTC
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 ?
Comment 3 Doug Quale 2005-03-16 07:35:30 UTC
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;
}
Comment 4 Matthias Clasen 2005-03-17 18:10:00 UTC
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)