[gnome-builder] vim: zl z<Right> and zh z<Left> in normal mode



commit 9e10f7e25ff0eab584750c4f5a994b6ae63d9a7f
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Thu Nov 19 00:17:18 2015 +0100

    vim: zl z<Right> and zh z<Left> in normal mode
    
    the [count] can be used too

 data/keybindings/vim.css           |    6 +++
 libide/ide-source-view-movements.c |   71 +++++++++++++++++++++++++++++++-----
 libide/ide-source-view.h           |   16 +++++++--
 3 files changed, 80 insertions(+), 13 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 70341d4..2356578 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -1249,6 +1249,12 @@
 
   bind "b" { "movement" (scroll-screen-bottom, 0, 0, 1) };
   bind "minus" { "movement" (scroll-screen-bottom, 0, 1, 1) };
+
+  bind "l" { "movement" (screen-left, 0, 0, 1) };
+  bind "Left" { "movement" (screen-left, 0, 0, 1) };
+
+  bind "h" { "movement" (screen-right, 0, 0, 1) };
+  bind "Right" { "movement" (screen-right, 0, 0, 1) };
 }
 
 @binding-set builder-vim-source-view-normal-Z
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index d03401e..21d6e54 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -23,6 +23,7 @@
 #include "ide-debug.h"
 #include "ide-enums.h"
 #include "ide-internal.h"
+#include "ide-cairo.h"
 #include "ide-source-iter.h"
 #include "ide-source-view-movements.h"
 #include "ide-vim-iter.h"
@@ -681,6 +682,48 @@ ide_source_view_movements_screen_bottom (Movement *mv)
 }
 
 static void
+ide_source_view_movements_scroll_by_chars (Movement *mv,
+                                           gint      chars)
+{
+  GtkTextView *text_view = (GtkTextView *)mv->self;
+  GtkAdjustment *hadj;
+  GtkTextBuffer *buffer;
+  GdkRectangle rect;
+  gdouble amount;
+  gdouble value;
+  gdouble new_value;
+  gdouble upper;
+  gdouble page_size;
+
+  if (chars == 0)
+    return;
+
+  hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (mv->self));
+  buffer = gtk_text_view_get_buffer (text_view);
+
+  gtk_text_view_get_iter_location (text_view, &mv->insert, &rect);
+
+  amount = chars * rect.width;
+
+  value = gtk_adjustment_get_value (hadj);
+  upper = gtk_adjustment_get_upper (hadj);
+  page_size = gtk_adjustment_get_page_size (hadj);
+
+  if (chars < 0 && value <= 0)
+    return;
+  else if (chars > 0 && value >= upper - page_size)
+    return;
+
+  new_value = CLAMP (value + amount, 0, upper - page_size);
+  gtk_adjustment_set_value (hadj, new_value);
+
+  if (chars > 0 && (rect.x < (gint)new_value))
+    gtk_text_view_get_iter_at_location (text_view, &mv->insert, new_value, rect.y);
+  else if (_ide_cairo_rectangle_x2 (&rect) > (gint)(new_value + page_size))
+    gtk_text_view_get_iter_at_location (text_view, &mv->insert, new_value + page_size - rect.width, rect.y);
+}
+
+static void
 ide_source_view_movements_scroll_by_lines (Movement *mv,
                                            gint      lines)
 {
@@ -723,7 +766,6 @@ ide_source_view_movements_scroll_by_lines (Movement *mv,
   upper = gtk_adjustment_get_upper (vadj);
   gtk_adjustment_set_value (vadj, CLAMP (value + amount, 0, upper));
 
-  mv->ignore_scroll_to_insert = TRUE;
   ide_source_view_place_cursor_onscreen (mv->self);
 }
 
@@ -734,15 +776,21 @@ ide_source_view_movements_scroll (Movement *mv)
   GtkTextMark *mark;
   gint count = MAX (1, mv->count);
 
-  if (mv->type == IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN)
+  if (mv->type == IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN ||
+      mv->type == IDE_SOURCE_VIEW_MOVEMENT_SCREEN_LEFT)
     count = -count;
 
-  ide_source_view_movements_scroll_by_lines (mv, count);
-
-  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (mv->self));
-  mark = gtk_text_buffer_get_insert (buffer);
-  gtk_text_buffer_get_iter_at_mark (buffer, &mv->insert, mark);
-  ide_source_view_move_mark_onscreen (mv->self, mark);
+  g_printf ("count:%i\n", count);
+  if (mv->type == IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN ||
+      mv->type == IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP)
+    {
+      ide_source_view_movements_scroll_by_lines (mv, count);
+      buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (mv->self));
+      mark = gtk_text_buffer_get_insert (buffer);
+      gtk_text_buffer_get_iter_at_mark (buffer, &mv->insert, mark);
+    }
+  else
+    ide_source_view_movements_scroll_by_chars (mv, count);
 
   mv->ignore_scroll_to_insert = TRUE;
 }
@@ -2210,6 +2258,8 @@ _ide_source_view_apply_movement (IdeSourceView         *self,
 
     case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP:
     case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN:
+    case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_LEFT:
+    case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_RIGHT:
     case IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP:
     case IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN:
       for (i = MAX (1, mv.count); i > 0; i--)
@@ -2218,8 +2268,9 @@ _ide_source_view_apply_movement (IdeSourceView         *self,
 
     case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN:
     case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP:
-      for (i = MAX (1, mv.count); i > 0; i--)
-        ide_source_view_movements_scroll (&mv);
+    case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_LEFT:
+    case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_RIGHT:
+      ide_source_view_movements_scroll (&mv);
       break;
 
     case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_TOP:
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index 4eb1e2f..a60bb8e 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -103,19 +103,25 @@ typedef enum
  *   inclusive will select the newline.
  * @IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP: move half a page up.
  * @IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN: move half a page down.
+ * @IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_LEFT: move half a page left.
+ * @IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_RIGHT: move half a page right.
  * @IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP: move a full page up.
  * @IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN: move a full page down.
  * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP: move to viewport up by visible line, adjusting cursor
  *   to stay on screen if necessary.
  * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN: move to viewport down by visible line, adjusting cursor
  *   to stay on screen if necessary.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_LEFT: move to viewport left by visible char, adjusting cursor
+ *   to stay on screen if necessary.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_RIGHT: move to viewport right by visible char, adjusting cursor
+ *   to stay on screen if necessary.
  * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_TOP: move to the top of the screen.
  * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_MIDDLE: move to the middle of the screen.
  * @IDE_SOURCE_VIEW_MOVEMENT_SCREEN_BOTTOM: move to the bottom of the screen.
  * @IDE_SOURCE_VIEW_MOVEMENT_MATCH_SPECIAL: move to match of brace, bracket, comment.
- * @IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_TOP: scroll until insert cursor is at screen top.
- * @IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_CENTER: scroll until insert cursor is at screen center.
- * @IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_BOTTOM: scroll until insert cursor is at screen bottom.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_TOP: scroll until insert cursor or [count]th line is at screen 
top.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_CENTER: scroll until insert cursor or [count]th line is at screen 
center.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_BOTTOM: scroll until insert cursor or [count]th line is at screen 
bottom.
  * @IDE_SOURCE_VIEW_MOVEMENT_NEXT_MATCH_SEARCH_CHAR: move to the next matching char according to f and t in 
vim.
  * @IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_MATCH_SEARCH_CHAR: move to the previous matching char according to F 
and T in vim.
  *
@@ -168,12 +174,16 @@ typedef enum
 
   IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP,
   IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN,
+  IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_LEFT,
+  IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_RIGHT,
 
   IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP,
   IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN,
 
   IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP,
   IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN,
+  IDE_SOURCE_VIEW_MOVEMENT_SCREEN_LEFT,
+  IDE_SOURCE_VIEW_MOVEMENT_SCREEN_RIGHT,
   IDE_SOURCE_VIEW_MOVEMENT_SCREEN_TOP,
   IDE_SOURCE_VIEW_MOVEMENT_SCREEN_MIDDLE,
   IDE_SOURCE_VIEW_MOVEMENT_SCREEN_BOTTOM,


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