[gnome-builder/wip/vim] vim: preserve selection on `j` command.



commit 55e5dd2f2d9a5faf1d5263f7594fed85e94e6999
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 30 14:06:06 2014 -0700

    vim: preserve selection on `j` command.

 src/editor/gb-editor-vim.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index 9b3bc20..8ef276f 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -460,6 +460,8 @@ gb_editor_vim_move_down (GbEditorVim *vim)
   GtkTextBuffer *buffer;
   GtkTextMark *insert;
   GtkTextIter iter;
+  GtkTextIter selection;
+  gboolean has_selection;
   guint line;
   guint offset;
 
@@ -468,15 +470,10 @@ gb_editor_vim_move_down (GbEditorVim *vim)
   priv = vim->priv;
 
   buffer = gtk_text_view_get_buffer (priv->text_view);
-  insert = gtk_text_buffer_get_insert (buffer);
-  gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+  has_selection = gb_editor_vim_get_selection_bounds (vim, &iter, &selection);
   line = gtk_text_iter_get_line (&iter);
   offset = vim->priv->target_line_offset;
 
-  /*
-   * TODO: handle there being a selection.
-   */
-
   gtk_text_buffer_get_iter_at_line (buffer, &iter, line + 1);
   if ((line + 1) == gtk_text_iter_get_line (&iter))
     {
@@ -484,9 +481,17 @@ gb_editor_vim_move_down (GbEditorVim *vim)
         if (!gtk_text_iter_ends_line (&iter))
           if (!gtk_text_iter_forward_char (&iter))
             break;
-      gtk_text_buffer_select_range (buffer, &iter, &iter);
+      if (has_selection)
+        {
+          if (gtk_text_iter_equal (&iter, &selection))
+            gtk_text_iter_forward_char (&iter);
+          gb_editor_vim_select_range (vim, &iter, &selection);
+        }
+      else
+        gtk_text_buffer_select_range (buffer, &iter, &iter);
     }
 
+  insert = gtk_text_buffer_get_insert (buffer);
   gtk_text_view_scroll_mark_onscreen (vim->priv->text_view, insert);
 }
 


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