[gnome-builder/gnome-builder-3-20] movements: add whole line page movements



commit 292f5a3d689725831cbc6bf98bca981e0642c3fa
Author: Christian Hergert <chergert redhat com>
Date:   Sat May 7 12:04:27 2016 +0300

    movements: add whole line page movements
    
    When moving by ctrl+f/b or page-up/down with linewise mode, we would drift
    from whole lines pretty quickly. This tries a bit harder to keep the line
    selection as whole lines.
    
    It could still use some work at the file edge boundaries, but this is
    clearly better than where we were.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=766087

 data/keybindings/vim.css           |    8 +++---
 libide/ide-source-view-movements.c |   42 ++++++++++++++++++++++++++++++++++++
 libide/ide-source-view.h           |    4 +++
 3 files changed, 50 insertions(+), 4 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index c2b40dc..3b59827 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -2318,13 +2318,13 @@ bind "KP_Multiply" { "save-insert-mark" ()
   bind "<ctrl>y" { "movement" (screen-down, 1, 0, 1) };
 
   /* page movements */
-  bind "<ctrl>b" { "movement" (page-up, 1, 0, 1)
+  bind "<ctrl>b" { "movement" (page-up-lines, 1, 0, 1)
                    "clear-count" () };
-  bind "Page_Up" { "movement" (page-up, 1, 0, 1)
+  bind "Page_Up" { "movement" (page-up-lines, 1, 0, 1)
                    "clear-count" () };
-  bind "<ctrl>f" { "movement" (page-down, 1, 0, 1)
+  bind "<ctrl>f" { "movement" (page-down-lines, 1, 0, 1)
                    "clear-count" () };
-  bind "Page_Down" { "movement" (page-down, 1, 0, 1)
+  bind "Page_Down" { "movement" (page-down-lines, 1, 0, 1)
                      "clear-count" () };
   bind "<ctrl>u" { "movement" (half-page-up, 1, 0, 1)
                    "clear-count" () };
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index 48cf6ca..96b37bb 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -859,6 +859,46 @@ ide_source_view_movements_move_page (Movement *mv)
       mv->ignore_scroll_to_insert = TRUE;
       break;
 
+    case IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP_LINES:
+      gtk_text_buffer_get_iter_at_line (buffer, &mv->insert, MAX (0, line_top - scrolloff));
+      if (!gtk_text_iter_ends_line (&mv->insert))
+        {
+          if (gtk_text_iter_compare (&mv->insert, &mv->selection) < 0)
+            gtk_text_iter_forward_line (&mv->insert);
+          else
+            gtk_text_iter_set_line_offset (&mv->insert, 0);
+        }
+      ide_source_view_movements_select_range (mv);
+
+      mark = _ide_source_view_get_scroll_mark (mv->self);
+      gtk_text_buffer_get_iter_at_line (buffer, &scroll_iter, line_top);
+      gtk_text_buffer_move_mark (buffer, mark, &scroll_iter);
+      gtk_text_view_scroll_to_mark (text_view, mark, 0.0, TRUE, 1.0, 1.0);
+
+      mv->ignore_select = TRUE;
+      mv->ignore_scroll_to_insert = TRUE;
+      break;
+
+    case IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN_LINES:
+      gtk_text_buffer_get_iter_at_line (buffer, &mv->insert, line_bottom + scrolloff);
+      if (!gtk_text_iter_ends_line (&mv->insert))
+        {
+          if (gtk_text_iter_compare (&mv->insert, &mv->selection) < 0)
+            gtk_text_iter_set_line_offset (&mv->insert, 0);
+          else
+            gtk_text_iter_forward_line (&mv->insert);
+        }
+      ide_source_view_movements_select_range (mv);
+
+      mark = _ide_source_view_get_scroll_mark (mv->self);
+      gtk_text_buffer_get_iter_at_line (buffer, &scroll_iter, line_bottom);
+      gtk_text_buffer_move_mark (buffer, mark, &scroll_iter);
+      gtk_text_view_scroll_to_mark (text_view, mark, 0.0, TRUE, 1.0, 0.0);
+
+      mv->ignore_select = TRUE;
+      mv->ignore_scroll_to_insert = TRUE;
+      break;
+
     case IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN:
       gtk_text_buffer_get_iter_at_line (buffer, &mv->insert, line_bottom + scrolloff);
       text_iter_forward_to_nonspace_captive (&mv->insert);
@@ -2134,7 +2174,9 @@ _ide_source_view_apply_movement (IdeSourceView         *self,
     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_UP_LINES:
     case IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN:
+    case IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN_LINES:
       for (i = MAX (1, mv.count); i > 0; i--)
         ide_source_view_movements_move_page (&mv);
       break;
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index d88cb99..3134b74 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -106,7 +106,9 @@ typedef enum
  * @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_UP_LINES: move a full page up, but extend to whole line.
  * @IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN: move a full page down.
+ * @IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN_LINES: move a full page down, but extend to whole line.
  * @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
@@ -180,7 +182,9 @@ typedef enum
   IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_RIGHT,
 
   IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP,
+  IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP_LINES,
   IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN,
+  IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN_LINES,
 
   IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP,
   IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN,


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