[gnome-builder/wip/vim] vim: preserve selection upon `w` command.



commit 4454a6dd83e870d850fe08d2c72a1aeb090b5fd1
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 30 14:03:03 2014 -0700

    vim: preserve selection upon `w` 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 2787797..9b3bc20 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -420,17 +420,14 @@ gb_editor_vim_move_forward_word (GbEditorVim *vim)
 {
   GtkTextBuffer *buffer;
   GtkTextIter iter;
+  GtkTextIter selection;
   GtkTextMark *insert;
+  gboolean has_selection;
 
   g_assert (GB_IS_EDITOR_VIM (vim));
 
   buffer = gtk_text_view_get_buffer (vim->priv->text_view);
-  insert = gtk_text_buffer_get_insert (buffer);
-  gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
-
-  /*
-   * TODO: handle there being a selection.
-   */
+  has_selection = gb_editor_vim_get_selection_bounds (vim, &iter, &selection);
 
   if (gtk_text_iter_inside_word (&iter))
     {
@@ -441,10 +438,18 @@ gb_editor_vim_move_forward_word (GbEditorVim *vim)
   if (gtk_text_iter_forward_word_end (&iter))
     gtk_text_iter_backward_word_start (&iter);
 
-  gtk_text_buffer_select_range (buffer, &iter, &iter);
+  if (has_selection)
+    {
+      if (gtk_text_iter_equal (&iter, &selection))
+        gtk_text_iter_forward_word_end (&iter);
+      gb_editor_vim_select_range (vim, &iter, &selection);
+    }
+  else
+    gtk_text_buffer_select_range (buffer, &iter, &iter);
 
   vim->priv->target_line_offset = gb_editor_vim_get_line_offset (vim);
 
+  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]