text: Be more selective when selecting on focus-in

We don't want to select on focus-in when the focus
comes from a child. The case where this does harm
is when you activate copy or paste actions from the
context menu. We close the menu before triggering the
action, and if that causes the text in the entry to
be selected, unexpected things happen, since the action
applies to the current selection.

Fixes: #2869
This commit is contained in:
Matthias Clasen 2020-06-26 15:49:39 -04:00
parent 8b4560cbfb
commit cd9f5733b3

View File

@ -3193,11 +3193,15 @@ gtk_text_grab_focus (GtkWidget *widget)
GtkText *self = GTK_TEXT (widget);
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
gboolean select_on_focus;
GtkWidget *prev_focus;
prev_focus = gtk_root_get_focus (gtk_widget_get_root (widget));
if (!GTK_WIDGET_CLASS (gtk_text_parent_class)->grab_focus (GTK_WIDGET (self)))
return FALSE;
if (priv->editable && !priv->in_click)
if (priv->editable && !priv->in_click &&
!(prev_focus && gtk_widget_is_ancestor (prev_focus, widget)))
{
g_object_get (gtk_widget_get_settings (widget),
"gtk-entry-select-on-focus",