[gnome-builder] editor: fix reselection of search text



commit b2c57b58d82e19d00bf17ec46d6b5781c62ff293
Author: Christian Hergert <chergert redhat com>
Date:   Thu Nov 30 17:53:17 2017 -0800

    editor: fix reselection of search text
    
    We had some code to block reselection because the notify callback in the
    revealer would reselect the text (causing it delete the previous text).
    
    This instead pushes that check off to the notify callback rather than
    in our core grab_focus case.
    
    This fixes reselection with ctrl+f while in the search box.

 src/libide/editor/ide-editor-search-bar.c |    6 +-----
 src/libide/editor/ide-editor-view.c       |   11 ++++++++++-
 2 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-search-bar.c b/src/libide/editor/ide-editor-search-bar.c
index 3da4775..a8286df 100644
--- a/src/libide/editor/ide-editor-search-bar.c
+++ b/src/libide/editor/ide-editor-search-bar.c
@@ -152,11 +152,7 @@ ide_editor_search_bar_grab_focus (GtkWidget *widget)
 
   g_assert (IDE_IS_EDITOR_SEARCH_BAR (self));
 
-  /* Be careful to not reselect or it can reselect the whole
-   * entry text (causing next character to overwrite).
-   */
-  if (!gtk_widget_has_focus (GTK_WIDGET (self->search_entry)))
-    gtk_widget_grab_focus (GTK_WIDGET (self->search_entry));
+  gtk_widget_grab_focus (GTK_WIDGET (self->search_entry));
 }
 
 static void
diff --git a/src/libide/editor/ide-editor-view.c b/src/libide/editor/ide-editor-view.c
index 5e92b21..35b72dd 100644
--- a/src/libide/editor/ide-editor-view.c
+++ b/src/libide/editor/ide-editor-view.c
@@ -111,7 +111,16 @@ ide_editor_view_notify_child_revealed (IdeEditorView *self,
   g_assert (GTK_IS_REVEALER (revealer));
 
   if (gtk_revealer_get_child_revealed (revealer))
-    gtk_widget_grab_focus (GTK_WIDGET (self->search_bar));
+    {
+      GtkWidget *toplevel = gtk_widget_get_ancestor (GTK_WIDGET (revealer), GTK_TYPE_WINDOW);
+      GtkWidget *focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
+
+      /* Only focus the search bar if it doesn't already have focus,
+       * as it can reselect the search text.
+       */
+      if (focus == NULL || !gtk_widget_is_ancestor (focus, GTK_WIDGET (revealer)))
+        gtk_widget_grab_focus (GTK_WIDGET (self->search_bar));
+    }
 }
 
 static void


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