diff --git a/ChangeLog b/ChangeLog index 7a2e12b058..4599acf4b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,20 @@ if the pointer is really over the returned widget, since the coordinate check may not always be hit in find_widget_under_pointer(). +2007-07-16 Matthias Clasen + + Fix some issues with some combinations of inline-selection + and inline-completion. (#457384, Christian Persch) + + * gtk/gtkentry.c (gtk_entry_completion_key_press): Don't store + the completion_prefix here, and be careful when using + completion_prefix, because it may be NULL. + * gtk/gtkentrycompletion.c (gtk_entry_completion_finalize): + Free completion_prefix here. + * gtk/gtkentrycompletion.c (gtk_entry_completion_real_insert_prefix): + (gtk_entry_completion_insert_completion_text): Store the + completion_prefix here. + 2007-07-16 Matthias Clasen * gtk/gtkfilechooserbutton.c (model_add_special_get_info_cb): diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 707aa90db7..6dba110ed1 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -5870,11 +5870,6 @@ gtk_entry_completion_key_press (GtkWidget *widget, if (!gtk_tree_selection_get_selected (sel, &model, &iter)) return FALSE; - if (completion->priv->completion_prefix == NULL) - { - completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry))); - } - g_signal_emit_by_name (completion, "cursor_on_match", model, &iter, &entry_set); } @@ -5906,7 +5901,11 @@ gtk_entry_completion_key_press (GtkWidget *widget, /* Escape rejects the tentative completion */ if (event->keyval == GDK_Escape) { - gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), completion->priv->completion_prefix); + if (completion->priv->completion_prefix) + gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), + completion->priv->completion_prefix); + else + gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), ""); } /* Move the cursor to the end for Right/Esc, to the diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c index b4c748aa3d..8c4268a794 100644 --- a/gtk/gtkentrycompletion.c +++ b/gtk/gtkentrycompletion.c @@ -650,6 +650,7 @@ gtk_entry_completion_finalize (GObject *object) g_object_unref (priv->action_view); g_free (priv->case_normalized_key); + g_free (priv->completion_prefix); if (priv->popup_window) gtk_widget_destroy (priv->popup_window); @@ -1634,6 +1635,9 @@ gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion, key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)); key_len = g_utf8_strlen (key, -1); + if (completion->priv->completion_prefix == NULL) + completion->priv->completion_prefix = g_strdup (key); + if (prefix_len > key_len) { gint pos = prefix_len; @@ -1674,44 +1678,28 @@ gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion, const gchar *text) { GtkEntryCompletionPrivate *priv = completion->priv; - gchar *needle; gint len; priv = completion->priv; if (priv->changed_id > 0) - { - g_signal_handler_block (priv->entry, - priv->changed_id); - } + g_signal_handler_block (priv->entry, priv->changed_id); if (priv->insert_text_id > 0) - { - g_signal_handler_block (completion->priv->entry, - completion->priv->insert_text_id); - } + g_signal_handler_block (priv->entry, priv->insert_text_id); - gtk_entry_set_text (GTK_ENTRY (priv->entry), text); - needle = strstr (text, completion->priv->completion_prefix); - if (needle) - { - len = g_utf8_strlen (text, -1) - g_utf8_strlen (needle, -1) - + g_utf8_strlen (priv->completion_prefix, -1); - gtk_editable_select_region (GTK_EDITABLE (priv->entry), - len, -1); - } + if (completion->priv->completion_prefix == NULL) + completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))); + gtk_entry_set_text (GTK_ENTRY (priv->entry), text); + + len = strlen (priv->completion_prefix); + gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1); if (priv->changed_id > 0) - { - g_signal_handler_unblock (priv->entry, - priv->changed_id); - } + g_signal_handler_unblock (priv->entry, priv->changed_id); if (priv->insert_text_id > 0) - { - g_signal_handler_unblock (priv->entry, - priv->insert_text_id); - } + g_signal_handler_unblock (priv->entry, priv->insert_text_id); } static gboolean