[gnome-builder] libide: add basic scroll movements
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add basic scroll movements
- Date: Mon, 23 Mar 2015 23:53:16 +0000 (UTC)
commit f798800518ccb2e4b05cff6fe893433ef70e71c6
Author: Christian Hergert <christian hergert me>
Date: Wed Mar 4 02:30:27 2015 -0800
libide: add basic scroll movements
data/keybindings/vim.css | 13 ++++++++++++
libide/ide-source-view-movements.c | 37 ++++++++++++++++++++++++++++++++++++
libide/ide-source-view.h | 7 ++++++
3 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 2a2ccdb..c24476d 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -60,6 +60,7 @@
/* screen movements, keeping cursor locked to visible region */
bind "<ctrl>e" { "movement" (screen-up, 0) };
bind "<ctrl>y" { "movement" (screen-down, 0) };
+ bind "z" { "set-mode" ("vim-normal-z", transient) };
/* move by paragraph */
bind "bracketleft" { "movement" (previous-paragraph, 0) };
@@ -113,6 +114,13 @@
bind "<ctrl>v" { "set-mode" ("vim-visual-block") };
}
+ binding-set builder-vim-source-view-normal-z
+{
+ bind "z" { "movement" (scroll-screen-center, 0) };
+ bind "t" { "movement" (scroll-screen-top, 0) };
+ bind "b" { "movement" (scroll-screen-bottom, 0) };
+}
+
@binding-set builder-vim-source-view-normal-y
{
bind "y" { "save-cursor" ()
@@ -168,6 +176,11 @@ IdeSourceViewMode.vim-normal-y {
builder-vim-source-view-normal-y;
}
+IdeSourceViewMode.vim-normal-z {
+ gtk-key-bindings: builder-vim-source-view,
+ builder-vim-source-view-normal-z;
+}
+
IdeSourceViewMode.vim-insert {
gtk-key-bindings: builder-vim-source-view, builder-vim-source-view-insert;
}
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index a3e1431..ed389d2 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -491,6 +491,37 @@ ide_source_view_movements_match_special (IdeSourceView *self,
ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
}
+static void
+ide_source_view_movements_scroll_center (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextView *text_view = (GtkTextView *)self;
+ GtkTextIter insert;
+ GtkTextIter selection;
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
+ switch ((int)movement)
+ {
+ case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_BOTTOM:
+ gtk_text_view_scroll_to_iter (text_view, &insert, 0.0, TRUE, 0.5, 1.0);
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_TOP:
+ gtk_text_view_scroll_to_iter (text_view, &insert, 0.0, TRUE, 0.5, 0.0);
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_CENTER:
+ gtk_text_view_scroll_to_iter (text_view, &insert, 0.0, TRUE, 0.5, 0.5);
+ break;
+
+ default:
+ break;
+ }
+}
+
void
_ide_source_view_apply_movement (IdeSourceView *self,
IdeSourceViewMovement movement,
@@ -621,6 +652,12 @@ _ide_source_view_apply_movement (IdeSourceView *self,
ide_source_view_movements_match_special (self, movement, extend_selection, param);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_TOP:
+ case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_CENTER:
+ case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_BOTTOM:
+ ide_source_view_movements_scroll_center (self, movement, extend_selection, param);
+ break;
+
default:
g_return_if_reached ();
}
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index 771be8c..d7a80d7 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -89,6 +89,9 @@ typedef enum
* @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.
*
* The type of movement.
*
@@ -138,6 +141,10 @@ typedef enum
IDE_SOURCE_VIEW_MOVEMENT_SCREEN_BOTTOM,
IDE_SOURCE_VIEW_MOVEMENT_MATCH_SPECIAL,
+
+ IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_TOP,
+ IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_CENTER,
+ IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_BOTTOM,
} IdeSourceViewMovement;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeSourceView, g_object_unref)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]