[gnome-text-editor] searchbar: simplify search movements



commit a2bace7f9cc055315a287b20e9dc5e69fab9380b
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 8 11:20:48 2021 -0700

    searchbar: simplify search movements
    
    This moves a bunch of our special case keybindings to the search entry
    which is where people are actually typing for search movements. We don't
    do this for the replace entry because that'd require disambiguating replace
    one with replace all.
    
    Additionally, we use Return/Enter to move to the next search result which
    feels a bit more natural to users coming from other systems. Using Control
    with Return/Enter will move you to the next result and dismiss the search
    bar.
    
    You can use Shift combined with Return/Enter to move backwards, and with
    Control Return/Enter to move backwards and dismiss the search bar.
    
    Hitting escape without moving to a search result will rubberband you back
    to where you started the search. While hitting escape after having moved
    to a search result will land you on the current search result.
    
    Fixes #177 and #156

 src/editor-page-actions.c | 10 ++++++----
 src/editor-page-private.h |  6 ++++--
 src/editor-page.c         | 10 ++++++----
 src/editor-search-bar.c   | 37 -------------------------------------
 src/editor-search-bar.ui  |  5 ++---
 src/editor-search-entry.c | 32 ++++++++++++++------------------
 6 files changed, 32 insertions(+), 68 deletions(-)
---
diff --git a/src/editor-page-actions.c b/src/editor-page-actions.c
index 160aca0..3898c4f 100644
--- a/src/editor-page-actions.c
+++ b/src/editor-page-actions.c
@@ -62,8 +62,9 @@ editor_page_actions_search_move_next (GtkWidget  *widget,
   EditorPage *self = (EditorPage *)widget;
 
   g_assert (EDITOR_IS_PAGE (self));
+  g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE_BOOLEAN));
 
-  _editor_page_move_next_search (self);
+  _editor_page_move_next_search (self, g_variant_get_boolean (param));
 }
 
 static void
@@ -74,8 +75,9 @@ editor_page_actions_search_move_previous (GtkWidget  *widget,
   EditorPage *self = (EditorPage *)widget;
 
   g_assert (EDITOR_IS_PAGE (self));
+  g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE_BOOLEAN));
 
-  _editor_page_move_previous_search (self);
+  _editor_page_move_previous_search (self, g_variant_get_boolean (param));
 }
 
 static void
@@ -217,9 +219,9 @@ _editor_page_class_actions_init (EditorPageClass *klass)
                                    editor_page_actions_goto_line);
   gtk_widget_class_install_action (widget_class, "search.hide", NULL,
                                    editor_page_actions_search_hide);
-  gtk_widget_class_install_action (widget_class, "search.move-next", NULL,
+  gtk_widget_class_install_action (widget_class, "search.move-next", "b",
                                    editor_page_actions_search_move_next);
-  gtk_widget_class_install_action (widget_class, "search.move-previous", NULL,
+  gtk_widget_class_install_action (widget_class, "search.move-previous", "b",
                                    editor_page_actions_search_move_previous);
   gtk_widget_class_install_action (widget_class, "search.replace-one", NULL,
                                    editor_page_actions_replace_one);
diff --git a/src/editor-page-private.h b/src/editor-page-private.h
index 7ef145f..6a3b936 100644
--- a/src/editor-page-private.h
+++ b/src/editor-page-private.h
@@ -85,7 +85,9 @@ void          _editor_page_begin_search           (EditorPage           *self);
 void          _editor_page_begin_replace          (EditorPage           *self);
 void          _editor_page_hide_search            (EditorPage           *self);
 void          _editor_page_scroll_to_insert       (EditorPage           *self);
-void          _editor_page_move_next_search       (EditorPage           *self);
-void          _editor_page_move_previous_search   (EditorPage           *self);
+void          _editor_page_move_next_search       (EditorPage           *self,
+                                                   gboolean              hide_after_search);
+void          _editor_page_move_previous_search   (EditorPage           *self,
+                                                   gboolean              hide_after_search);
 
 G_END_DECLS
diff --git a/src/editor-page.c b/src/editor-page.c
index 585de10..038c8c4 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -1139,19 +1139,21 @@ _editor_page_scroll_to_insert (EditorPage *self)
 }
 
 void
-_editor_page_move_next_search (EditorPage *self)
+_editor_page_move_next_search (EditorPage *self,
+                               gboolean    hide_after_move)
 {
   g_return_if_fail (EDITOR_IS_PAGE (self));
 
-  _editor_search_bar_move_next (self->search_bar, FALSE);
+  _editor_search_bar_move_next (self->search_bar, hide_after_move);
 }
 
 void
-_editor_page_move_previous_search (EditorPage *self)
+_editor_page_move_previous_search (EditorPage *self,
+                                   gboolean    hide_after_move)
 {
   g_return_if_fail (EDITOR_IS_PAGE (self));
 
-  _editor_search_bar_move_previous (self->search_bar, FALSE);
+  _editor_search_bar_move_previous (self->search_bar, hide_after_move);
 }
 
 static void
diff --git a/src/editor-search-bar.c b/src/editor-search-bar.c
index 0844459..c7e2700 100644
--- a/src/editor-search-bar.c
+++ b/src/editor-search-bar.c
@@ -72,7 +72,6 @@ enum {
 enum {
   MOVE_NEXT_SEARCH,
   MOVE_PREVIOUS_SEARCH,
-  HIDE_SEARCH,
   N_SIGNALS
 };
 
@@ -128,16 +127,6 @@ editor_search_bar_scroll_to_insert (EditorSearchBar *self)
     _editor_page_scroll_to_insert (EDITOR_PAGE (page));
 }
 
-static void
-editor_search_bar_search_activate_cb (EditorSearchBar   *self,
-                                      EditorSearchEntry *entry)
-{
-  g_assert (EDITOR_IS_SEARCH_BAR (self));
-  g_assert (EDITOR_IS_SEARCH_ENTRY (entry));
-
-  _editor_search_bar_move_next (self, TRUE);
-}
-
 static void
 editor_search_bar_move_next_forward_cb (GObject      *object,
                                         GAsyncResult *result,
@@ -225,14 +214,6 @@ _editor_search_bar_move_previous (EditorSearchBar *self,
                                             g_object_ref (self));
 }
 
-static void
-editor_search_bar_hide_search_cb (EditorSearchBar *self)
-{
-  g_assert (EDITOR_IS_SEARCH_BAR (self));
-
-  gtk_widget_activate_action (GTK_WIDGET (self), "search.hide", NULL);
-}
-
 static gboolean
 text_to_search_text (GBinding     *binding,
                      const GValue *from_value,
@@ -458,7 +439,6 @@ editor_search_bar_class_init (EditorSearchBarClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorSearchBar, replace_mode_button);
   gtk_widget_class_bind_template_child (widget_class, EditorSearchBar, search_entry);
   gtk_widget_class_bind_template_child (widget_class, EditorSearchBar, word_button);
-  gtk_widget_class_bind_template_callback (widget_class, editor_search_bar_search_activate_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_search_key_pressed_cb);
 
   signals [MOVE_NEXT_SEARCH] =
@@ -479,24 +459,7 @@ editor_search_bar_class_init (EditorSearchBarClass *klass)
                                 NULL,
                                 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 
-  signals [HIDE_SEARCH] =
-    g_signal_new_class_handler ("hide-search",
-                                G_TYPE_FROM_CLASS (klass),
-                                G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                                G_CALLBACK (editor_search_bar_hide_search_cb),
-                                NULL, NULL,
-                                NULL,
-                                G_TYPE_NONE, 0);
-
   gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Escape, 0, "search.hide", NULL);
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_g, GDK_CONTROL_MASK|GDK_SHIFT_MASK, 
"search.move-previous-search", NULL);
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_g, GDK_CONTROL_MASK, "search.move-next-search", 
NULL);
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Down, 0, "search.move-next-search", NULL);
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Up, 0, "search.move-previous-search", NULL);
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, 0, "search.move-next-search", NULL);
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, 0, "search.move-next-search", NULL);
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_SHIFT_MASK, 
"search.move-previous-search", NULL);
-  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, GDK_SHIFT_MASK, 
"search.move-previous-search", NULL);
 
   properties [PROP_MODE] =
     g_param_spec_enum ("mode",
diff --git a/src/editor-search-bar.ui b/src/editor-search-bar.ui
index 8f03f23..dfe9f44 100644
--- a/src/editor-search-bar.ui
+++ b/src/editor-search-bar.ui
@@ -12,7 +12,6 @@
         <child>
           <object class="EditorSearchEntry" id="search_entry">
             <property name="hexpand">true</property>
-            <signal name="activate" handler="editor_search_bar_search_activate_cb" swapped="true" 
object="EditorSearchBar"/>
             <layout>
               <property name="row">0</property>
               <property name="column">0</property>
@@ -47,14 +46,14 @@
             </style>
             <child>
               <object class="GtkButton">
-                <property name="action-name">search.move-previous</property>
+                <property name="action-name">search.move-previous(false)</property>
                 <property name="tooltip-text" translatable="yes">Move to previous match 
(Ctrl+Shift+G)</property>
                 <property name="icon-name">go-up-symbolic</property>
               </object>
             </child>
             <child>
               <object class="GtkButton">
-                <property name="action-name">search.move-next</property>
+                <property name="action-name">search.move-next(false)</property>
                 <property name="tooltip-text" translatable="yes">Move to next match (Ctrl+G)</property>
                 <property name="icon-name">go-down-symbolic</property>
               </object>
diff --git a/src/editor-search-entry.c b/src/editor-search-entry.c
index 8d602b8..b8fc220 100644
--- a/src/editor-search-entry.c
+++ b/src/editor-search-entry.c
@@ -40,13 +40,6 @@ static void editable_iface_init (GtkEditableInterface *iface);
 G_DEFINE_TYPE_WITH_CODE (EditorSearchEntry, editor_search_entry, GTK_TYPE_WIDGET,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE, editable_iface_init))
 
-enum {
-  ACTIVATE,
-  N_SIGNALS
-};
-
-static guint signals[N_SIGNALS];
-
 GtkWidget *
 editor_search_entry_new (void)
 {
@@ -66,7 +59,7 @@ on_text_activate_cb (EditorSearchEntry *self,
   g_assert (EDITOR_IS_SEARCH_ENTRY (self));
   g_assert (GTK_IS_TEXT (text));
 
-  g_signal_emit (self, signals [ACTIVATE], 0);
+  gtk_widget_activate_action (GTK_WIDGET (self), "search.move-next", "b", FALSE);
 }
 
 static void
@@ -139,16 +132,6 @@ editor_search_entry_class_init (EditorSearchEntryClass *klass)
 
   gtk_editable_install_properties (object_class, 1);
 
-  signals[ACTIVATE] =
-    g_signal_new ("activate",
-                  G_TYPE_FROM_CLASS (klass),
-                  G_SIGNAL_RUN_LAST,
-                  0,
-                  NULL, NULL,
-                  NULL,
-                  G_TYPE_NONE, 0);
-
-  gtk_widget_class_set_activate_signal (widget_class, signals[ACTIVATE]);
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
   gtk_widget_class_set_css_name (widget_class, "entry");
   gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_TEXT_BOX);
@@ -157,6 +140,19 @@ editor_search_entry_class_init (EditorSearchEntryClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorSearchEntry, text);
   gtk_widget_class_bind_template_callback (widget_class, on_text_activate_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_text_notify_cb);
+
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_g, GDK_CONTROL_MASK|GDK_SHIFT_MASK, 
"search.move-previous", "b", FALSE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_g, GDK_CONTROL_MASK, "search.move-next", "b", 
FALSE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Down, 0, "search.move-next", "b", FALSE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Up, 0, "search.move-previous", "b", FALSE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, 0, "search.move-next", "b", FALSE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, 0, "search.move-next", "b", FALSE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_SHIFT_MASK, "search.move-previous", 
"b", FALSE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, GDK_SHIFT_MASK, 
"search.move-previous", "b", FALSE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_CONTROL_MASK, "search.move-next", 
"b", TRUE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, GDK_CONTROL_MASK, "search.move-next", 
"b", TRUE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_Return, GDK_CONTROL_MASK|GDK_SHIFT_MASK, 
"search.move-previous", "b", TRUE);
+  gtk_widget_class_add_binding_action (widget_class, GDK_KEY_KP_Enter, GDK_CONTROL_MASK|GDK_SHIFT_MASK, 
"search.move-previous", "b", TRUE);
 }
 
 static void


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