[gnome-builder/wip/vim] vim: indent/unindent selection upon > or < key press.



commit a2c4dab1546b647fe70524e94aeecaa500637bfb
Author: Christian Hergert <christian hergert me>
Date:   Mon Sep 29 16:44:27 2014 -0700

    vim: indent/unindent selection upon > or < key press.

 src/editor/gb-editor-vim.c |   45 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index 63bb17f..09c55c9 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -548,6 +548,21 @@ gb_editor_vim_insert_nl_after (GbEditorVim *vim)
 }
 
 static gboolean
+gb_editor_vim_has_selection (GbEditorVim *vim)
+{
+  GtkTextBuffer *buffer;
+  GtkTextIter begin;
+  GtkTextIter end;
+
+  g_assert (GB_IS_EDITOR_VIM (vim));
+
+  buffer = gtk_text_view_get_buffer (vim->priv->text_view);
+  gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+
+  return !gtk_text_iter_equal (&begin, &end);
+}
+
+static gboolean
 gb_editor_vim_handle_normal (GbEditorVim *vim,
                              GdkEventKey *event)
 {
@@ -683,11 +698,37 @@ gb_editor_vim_handle_normal (GbEditorVim *vim,
 
       break;
 
+    case GDK_KEY_greater:
+      /*
+       * If we have a selection, try to indent it.
+       */
+      if (gb_editor_vim_has_selection (vim) &&
+          GB_IS_SOURCE_VIEW (vim->priv->text_view))
+        {
+          GbSourceView *view = GB_SOURCE_VIEW (vim->priv->text_view);
+          gb_source_view_indent_selection (view);
+          return TRUE;
+        }
+
+      break;
+
+    case GDK_KEY_less:
+      /*
+       * If we have a selection, try to unindent it.
+       */
+      if (gb_editor_vim_has_selection (vim) &&
+          GB_IS_SOURCE_VIEW (vim->priv->text_view))
+        {
+          GbSourceView *view = GB_SOURCE_VIEW (vim->priv->text_view);
+          gb_source_view_unindent_selection (view);
+          return TRUE;
+        }
+
+      break;
+
     /*
      * TODO:
      *
-     *   - Shift in with >
-     *   - Shift out with <
      *   - Selection with v
      *   - auto-indent on o and O
      */


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