[gnome-builder/wip/vim] editor: allow specifying the initial text and and direction for search.



commit 82ee886cdc9dfbf9045f54fc89b5087d0814ccff
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 30 10:56:15 2014 -0700

    editor: allow specifying the initial text and and direction for search.
    
    This can then be used by features like # in VIM to jump backwards in
    the buffer immediately.

 src/editor/gb-editor-commands.c |    2 +-
 src/editor/gb-editor-tab.c      |   12 +++++++++---
 src/editor/gb-editor-vim.c      |    2 +-
 src/editor/gb-source-view.c     |   12 +++++++-----
 src/editor/gb-source-view.h     |    2 ++
 5 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/src/editor/gb-editor-commands.c b/src/editor/gb-editor-commands.c
index 738caae..2370e32 100644
--- a/src/editor/gb-editor-commands.c
+++ b/src/editor/gb-editor-commands.c
@@ -218,7 +218,7 @@ gb_editor_commands_find (GbEditorWorkspace *workspace,
 {
   ENTRY;
   g_return_if_fail (GB_IS_EDITOR_TAB (tab));
-  gb_source_view_begin_search (tab->priv->source_view, NULL);
+  gb_source_view_begin_search (tab->priv->source_view, GTK_DIR_DOWN, NULL);
   EXIT;
 }
 
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 0564546..47dce52 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -885,9 +885,10 @@ on_source_view_push_snippet (GbSourceView           *source_view,
 }
 
 static void
-on_source_view_begin_search (GbSourceView *source_view,
-                             const gchar  *search_text,
-                             GbEditorTab  *tab)
+on_source_view_begin_search (GbSourceView     *source_view,
+                             GtkDirectionType  direction,
+                             const gchar      *search_text,
+                             GbEditorTab      *tab)
 {
   GbEditorTabPrivate *priv;
 
@@ -902,6 +903,11 @@ on_source_view_begin_search (GbSourceView *source_view,
   gtk_revealer_set_reveal_child (priv->revealer, TRUE);
   gtk_source_search_context_set_highlight (priv->search_context, TRUE);
   gtk_widget_grab_focus (GTK_WIDGET (priv->search_entry));
+
+  if (direction == GTK_DIR_DOWN)
+    gb_editor_tab_move_next_match (tab);
+  else if (direction == GTK_DIR_UP)
+    gb_editor_tab_move_previous_match (tab);
 }
 
 void
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index d622ffc..57dc4ba 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -1152,7 +1152,7 @@ gb_editor_vim_handle_normal (GbEditorVim *vim,
       if (GB_IS_SOURCE_VIEW (vim->priv->text_view))
         {
           gb_source_view_begin_search (GB_SOURCE_VIEW (vim->priv->text_view),
-                                       NULL);
+                                       GTK_DIR_DOWN, NULL);
           return TRUE;
         }
 
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index 294dbc3..e2d8fe5 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -75,12 +75,13 @@ static GParamSpec *gParamSpecs [LAST_PROP];
 static guint       gSignals [LAST_SIGNAL];
 
 void
-gb_source_view_begin_search (GbSourceView *view,
-                             const gchar  *search_text)
+gb_source_view_begin_search (GbSourceView     *view,
+                             GtkDirectionType  direction,
+                             const gchar      *search_text)
 {
   g_return_if_fail (GB_IS_SOURCE_VIEW (view));
 
-  g_signal_emit (view, gSignals [BEGIN_SEARCH], 0, search_text);
+  g_signal_emit (view, gSignals [BEGIN_SEARCH], 0, direction, search_text);
 }
 
 static void
@@ -1479,9 +1480,10 @@ gb_source_view_class_init (GbSourceViewClass *klass)
                   G_STRUCT_OFFSET (GbSourceViewClass, begin_search),
                   NULL,
                   NULL,
-                  g_cclosure_marshal_VOID__STRING,
+                  NULL,
                   G_TYPE_NONE,
-                  1,
+                  2,
+                  GTK_TYPE_DIRECTION_TYPE,
                   G_TYPE_STRING);
 }
 
diff --git a/src/editor/gb-source-view.h b/src/editor/gb-source-view.h
index af4081e..0cb6775 100644
--- a/src/editor/gb-source-view.h
+++ b/src/editor/gb-source-view.h
@@ -57,6 +57,7 @@ struct _GbSourceViewClass
   void (*pop_snippet)  (GbSourceView           *view,
                         GbSourceSnippet        *snippet);
   void (*begin_search) (GbSourceView           *view,
+                        GtkDirectionType        direction,
                         const gchar            *search_text);
 };
 
@@ -71,6 +72,7 @@ GbSourceAutoIndenter *gb_source_view_get_auto_indenter  (GbSourceView         *v
 void                  gb_source_view_set_auto_indenter  (GbSourceView         *view,
                                                          GbSourceAutoIndenter *auto_indenter);
 void                  gb_source_view_begin_search       (GbSourceView         *view,
+                                                         GtkDirectionType      direction,
                                                          const gchar          *search_text);
 void                  gb_source_view_indent_selection   (GbSourceView         *view);
 void                  gb_source_view_unindent_selection (GbSourceView         *view);


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