[gnome-builder/wip/vim] vim: preserve selected character column when moving up and down.



commit 2734dcac918c2962e3d5b68f3fce02a1fc0a3be7
Author: Christian Hergert <christian hergert me>
Date:   Thu Oct 2 02:11:16 2014 -0700

    vim: preserve selected character column when moving up and down.

 src/editor/gb-editor-vim.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index c9c1106..e5c32f6 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -863,6 +863,26 @@ is_single_line_selection (const GtkTextIter *begin,
              gtk_text_iter_get_line (begin)));
 }
 
+static gboolean
+is_single_char_selection (const GtkTextIter *begin,
+                          const GtkTextIter *end)
+{
+  GtkTextIter tmp;
+
+  g_assert (begin);
+  g_assert (end);
+
+  gtk_text_iter_assign (&tmp, begin);
+  if (gtk_text_iter_forward_char (&tmp) && gtk_text_iter_equal (&tmp, end))
+    return TRUE;
+
+  gtk_text_iter_assign (&tmp, end);
+  if (gtk_text_iter_forward_char (&tmp) && gtk_text_iter_equal (&tmp, begin))
+    return TRUE;
+
+  return FALSE;
+}
+
 static void
 text_iter_swap (GtkTextIter *a,
                 GtkTextIter *b)
@@ -911,6 +931,12 @@ gb_editor_vim_move_down (GbEditorVim *vim)
       GOTO (move_mark);
     }
 
+  if (is_single_char_selection (&iter, &selection))
+    {
+      if (gtk_text_iter_compare (&iter, &selection) < 0)
+        priv->target_line_offset = ++offset;
+    }
+
   gtk_text_buffer_get_iter_at_line (buffer, &iter, line + 1);
   if ((line + 1) == gtk_text_iter_get_line (&iter))
     {
@@ -966,6 +992,12 @@ gb_editor_vim_move_up (GbEditorVim *vim)
       GOTO (move_mark);
     }
 
+  if (is_single_char_selection (&iter, &selection))
+    {
+      if (gtk_text_iter_compare (&iter, &selection) > 0)
+        priv->target_line_offset = --offset;
+    }
+
   gtk_text_buffer_get_iter_at_line (buffer, &iter, line - 1);
   if ((line - 1) == gtk_text_iter_get_line (&iter))
     {


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