[gnome-builder] vim: save search direction



commit ac5a3869e0cf7ee5278200b975edf4b73b748829
Author: Ray Strode <rstrode redhat com>
Date:   Tue Jan 27 22:31:40 2015 -0500

    vim: save search direction
    
    We're going to need the search direction to implement the
    'n' command, since the 'n' command replays the last search
    in the direction of the last search.
    
    This commit saves the search direction from the '*' and '#'
    commands in a new search-direction property on the vim object.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=743668

 src/vim/gb-source-vim.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/vim/gb-source-vim.h |    5 +++++
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/vim/gb-source-vim.c b/src/vim/gb-source-vim.c
index b181a7a..03cec23 100644
--- a/src/vim/gb-source-vim.c
+++ b/src/vim/gb-source-vim.c
@@ -78,6 +78,7 @@ struct _GbSourceVimPrivate
   GtkTextMark             *selection_anchor_end;
   GtkSourceSearchContext  *search_context;
   GtkSourceSearchSettings *search_settings;
+  GtkDirectionType         search_direction;
   GPtrArray               *captured_events;
   GbSourceVimMode          mode;
   GSettings               *vim_settings;
@@ -185,6 +186,7 @@ enum
   PROP_MODE,
   PROP_PHRASE,
   PROP_SEARCH_TEXT,
+  PROP_SEARCH_DIRECTION,
   PROP_TEXT_VIEW,
   LAST_PROP
 };
@@ -2438,6 +2440,8 @@ gb_source_vim_reverse_search (GbSourceVim *vim)
   if (!GTK_SOURCE_IS_VIEW (vim->priv->text_view))
     return;
 
+  gb_source_vim_set_search_direction (vim, GTK_DIR_UP);
+
   if (gb_source_vim_select_current_word (vim, &begin, &end))
     {
       GtkTextIter start_iter;
@@ -2485,6 +2489,8 @@ gb_source_vim_search (GbSourceVim *vim)
   if (!GTK_SOURCE_IS_VIEW (vim->priv->text_view))
     return;
 
+  gb_source_vim_set_search_direction (vim, GTK_DIR_DOWN);
+
   has_selection = gb_source_vim_get_selection_bounds (vim, &iter, &selection);
 
   if (has_selection)
@@ -3713,6 +3719,26 @@ gb_source_vim_set_search_text (GbSourceVim     *vim,
   g_object_notify_by_pspec (G_OBJECT (vim), gParamSpecs [PROP_SEARCH_TEXT]);
 }
 
+GtkDirectionType
+gb_source_vim_get_search_direction (GbSourceVim *vim)
+{
+  g_return_val_if_fail (GB_IS_SOURCE_VIM (vim), GTK_DIR_DOWN);
+
+  return vim->priv->search_direction;
+}
+
+void
+gb_source_vim_set_search_direction (GbSourceVim      *vim,
+                                    GtkDirectionType  search_direction)
+{
+  if (vim->priv->search_direction == search_direction)
+    return;
+
+  vim->priv->search_direction = search_direction;
+
+  g_object_notify_by_pspec (G_OBJECT (vim), gParamSpecs [PROP_SEARCH_DIRECTION]);
+}
+
 GtkWidget *
 gb_source_vim_get_text_view (GbSourceVim *vim)
 {
@@ -4355,6 +4381,10 @@ gb_source_vim_get_property (GObject    *object,
       g_value_set_string (value, gb_source_vim_get_search_text (vim));
       break;
 
+    case PROP_SEARCH_DIRECTION:
+      g_value_set_enum (value, gb_source_vim_get_search_direction (vim));
+      break;
+
     case PROP_TEXT_VIEW:
       g_value_set_object (value, gb_source_vim_get_text_view (vim));
       break;
@@ -4382,6 +4412,10 @@ gb_source_vim_set_property (GObject      *object,
       gb_source_vim_set_search_text (vim, g_value_get_string (value));
       break;
 
+    case PROP_SEARCH_DIRECTION:
+      gb_source_vim_set_search_direction (vim, g_value_get_enum (value));
+      break;
+
     case PROP_TEXT_VIEW:
       gb_source_vim_set_text_view (vim, g_value_get_object (value));
       break;
@@ -5375,6 +5409,17 @@ gb_source_vim_class_init (GbSourceVimClass *klass)
   g_object_class_install_property (object_class, PROP_SEARCH_TEXT,
                                    gParamSpecs [PROP_SEARCH_TEXT]);
 
+  gParamSpecs [PROP_SEARCH_DIRECTION] =
+    g_param_spec_enum ("search-direction",
+                       _("Search Direction"),
+                       _("The direction of the last text searched for."),
+                       GTK_TYPE_DIRECTION_TYPE,
+                       GTK_DIR_DOWN,
+                       (G_PARAM_READWRITE |
+                        G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_SEARCH_DIRECTION,
+                                   gParamSpecs [PROP_SEARCH_DIRECTION]);
+
   gParamSpecs [PROP_TEXT_VIEW] =
     g_param_spec_object ("text-view",
                          _("Text View"),
@@ -5720,6 +5765,7 @@ gb_source_vim_init (GbSourceVim *vim)
   vim->priv->mode = 0;
   vim->priv->phrase = g_string_new (NULL);
   vim->priv->search_settings = gtk_source_search_settings_new ();
+  vim->priv->search_direction = GTK_DIR_DOWN;
   vim->priv->captured_events =
     g_ptr_array_new_with_free_func ((GDestroyNotify)gdk_event_free);
 
diff --git a/src/vim/gb-source-vim.h b/src/vim/gb-source-vim.h
index a7020f2..c5b268b 100644
--- a/src/vim/gb-source-vim.h
+++ b/src/vim/gb-source-vim.h
@@ -98,6 +98,11 @@ void             gb_source_vim_set_enabled      (GbSourceVim     *vim,
 const gchar     *gb_source_vim_get_search_text  (GbSourceVim     *vim);
 void             gb_source_vim_set_search_text  (GbSourceVim     *vim,
                                                  const gchar     *text);
+
+GtkDirectionType gb_source_vim_get_search_direction (GbSourceVim      *vim);
+void             gb_source_vim_set_search_direction (GbSourceVim      *vim,
+                                                     GtkDirectionType  dir);
+
 GtkWidget       *gb_source_vim_get_text_view    (GbSourceVim     *vim);
 gboolean         gb_source_vim_execute_command  (GbSourceVim     *vim,
                                                  const gchar     *command);


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