[gnome-builder] editor: allow keeping search box visible on view focus-in



commit fc5ff1caade473883b237f03969b963f3d3e7be3
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 6 16:10:39 2019 -0800

    editor: allow keeping search box visible on view focus-in
    
    We try to only keep the search context alive while the bar is visible. To
    allow for the results to stick around, we can allow keeping the search bar
    visible by clicking somewhere in the document.
    
    To allow for this, we need to clear the saved bit in the source view so
    that returning to the source view does not cause focus-in-event tracking
    to restore the previous cursor position.
    
    Fixes #792

 src/libide/editor/ide-editor-page.c             |  2 --
 src/libide/editor/ide-editor-search-bar.c       | 23 ++++++++++++++++++++---
 src/libide/editor/ide-editor-search.c           |  8 +++++++-
 src/libide/sourceview/ide-source-view-private.h | 15 ++++++++-------
 src/libide/sourceview/ide-source-view.c         | 10 ++++++++++
 5 files changed, 45 insertions(+), 13 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-page.c b/src/libide/editor/ide-editor-page.c
index e31a8b22e..a8ad0c5bf 100644
--- a/src/libide/editor/ide-editor-page.c
+++ b/src/libide/editor/ide-editor-page.c
@@ -176,8 +176,6 @@ ide_editor_page_focus_in_event (IdeEditorPage *self,
   g_assert (IDE_IS_EDITOR_PAGE (self));
   g_assert (IDE_IS_SOURCE_VIEW (source_view));
 
-  gtk_revealer_set_reveal_child (self->search_revealer, FALSE);
-
   ide_page_mark_used (IDE_PAGE (self));
 
   return GDK_EVENT_PROPAGATE;
diff --git a/src/libide/editor/ide-editor-search-bar.c b/src/libide/editor/ide-editor-search-bar.c
index aab076aa7..0fd0de533 100644
--- a/src/libide/editor/ide-editor-search-bar.c
+++ b/src/libide/editor/ide-editor-search-bar.c
@@ -28,6 +28,7 @@
 #include "ide-editor-private.h"
 #include "ide-editor-search.h"
 #include "ide-editor-search-bar.h"
+#include "ide-source-view-private.h"
 
 struct _IdeEditorSearchBar
 {
@@ -232,9 +233,25 @@ search_entry_activate (IdeEditorSearchBar *self,
 
   if (self->search != NULL)
     {
-      ide_editor_search_set_extend_selection (self->search, IDE_EDITOR_SEARCH_SELECT_NONE);
-      ide_editor_search_set_repeat (self->search, 0);
-      ide_editor_search_move (self->search, IDE_EDITOR_SEARCH_NEXT);
+      GtkWidget *page;
+
+      /* If the user is already on a match occurrence, then we don't
+       * want to advance them to the next position (instead, we'll drop
+       * them back in the editor at the current position.
+       */
+      if (ide_editor_search_get_match_position (self->search) == 0)
+        {
+          ide_editor_search_set_extend_selection (self->search, IDE_EDITOR_SEARCH_SELECT_NONE);
+          ide_editor_search_set_repeat (self->search, 0);
+          ide_editor_search_move (self->search, IDE_EDITOR_SEARCH_NEXT);
+        }
+
+      if ((page = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_EDITOR_PAGE)))
+        {
+          IdeSourceView *view = ide_editor_page_get_view (IDE_EDITOR_PAGE (page));
+
+          _ide_source_view_clear_saved_mark (view);
+        }
     }
 
   g_signal_emit (self, signals [STOP_SEARCH], 0);
diff --git a/src/libide/editor/ide-editor-search.c b/src/libide/editor/ide-editor-search.c
index d44c869e0..f16f0eef1 100644
--- a/src/libide/editor/ide-editor-search.c
+++ b/src/libide/editor/ide-editor-search.c
@@ -945,7 +945,13 @@ ide_editor_search_scan_forward_cb (GObject      *object,
   if (r == TRUE)
     {
       /* Scan forward to the location of the next match */
-      gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (self->view), &begin, 0.0, TRUE, 1.0, 0.5);
+      ide_source_view_scroll_to_iter (IDE_SOURCE_VIEW (self->view),
+                                      &begin,
+                                      0.0,
+                                      IDE_SOURCE_SCROLL_BOTH,
+                                      1.0,
+                                      0.5,
+                                      FALSE);
     }
   else if (self->interactive > 0)
     {
diff --git a/src/libide/sourceview/ide-source-view-private.h b/src/libide/sourceview/ide-source-view-private.h
index 6c9be3a64..00e038a31 100644
--- a/src/libide/sourceview/ide-source-view-private.h
+++ b/src/libide/sourceview/ide-source-view-private.h
@@ -24,12 +24,13 @@
 
 G_BEGIN_DECLS
 
-void         _ide_source_view_init_shortcuts  (IdeSourceView *self);
-const gchar *_ide_source_view_get_mode_name   (IdeSourceView *self);
-void         _ide_source_view_set_count       (IdeSourceView *self,
-                                               gint           count);
-void         _ide_source_view_set_modifier    (IdeSourceView *self,
-                                               gunichar       modifier);
-GtkTextMark *_ide_source_view_get_scroll_mark (IdeSourceView *self);
+void         _ide_source_view_init_shortcuts   (IdeSourceView *self);
+const gchar *_ide_source_view_get_mode_name    (IdeSourceView *self);
+void         _ide_source_view_set_count        (IdeSourceView *self,
+                                                gint           count);
+void         _ide_source_view_set_modifier     (IdeSourceView *self,
+                                                gunichar       modifier);
+GtkTextMark *_ide_source_view_get_scroll_mark  (IdeSourceView *self);
+void         _ide_source_view_clear_saved_mark (IdeSourceView *self);
 
 G_END_DECLS
diff --git a/src/libide/sourceview/ide-source-view.c b/src/libide/sourceview/ide-source-view.c
index f41639859..62c8d9255 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -3454,6 +3454,16 @@ ide_source_view_real_restore_insert_mark (IdeSourceView *self)
   ide_source_view_real_restore_insert_mark_full (self, TRUE);
 }
 
+void
+_ide_source_view_clear_saved_mark (IdeSourceView *self)
+{
+  IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_SOURCE_VIEW (self));
+
+  priv->insert_mark_cleared = TRUE;
+}
+
 static void
 ide_source_view_real_save_insert_mark (IdeSourceView *self)
 {


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