[gnome-builder] libide: add paragraph movements



commit 7d94f6c3bdc07606808e47fadac53a3c2d70bb2f
Author: Christian Hergert <christian hergert me>
Date:   Wed Mar 4 18:16:42 2015 -0800

    libide: add paragraph movements

 data/keybindings/vim.css           |    4 +-
 libide/ide-source-view-movements.c |   56 ++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index eedc045..074895a 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -76,8 +76,8 @@
   bind "z" { "set-mode" ("vim-normal-z", transient) };
 
   /* move by paragraph */
-  bind "bracketleft" { "movement" (previous-paragraph, 0) };
-  bind "bracketright" { "movement" (next-paragraph, 0) };
+  bind "braceleft" { "movement" (paragraph-start, 0) };
+  bind "braceright" { "movement" (paragraph-end, 0) };
 
   /* move by sentance */
   bind "parenleft" { "movement" (previous-sentance, 0) };
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index 1ca79dc..0ce2ff0 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -790,6 +790,60 @@ ide_source_view_movements_previous_word_end (IdeSourceView         *self,
   ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
 }
 
+static void
+ide_source_view_movements_paragraph_start (IdeSourceView         *self,
+                                          IdeSourceViewMovement  movement,
+                                          gboolean               extend_selection,
+                                          gint                   param)
+{
+  GtkTextIter insert;
+  GtkTextIter selection;
+
+  g_assert (IDE_IS_SOURCE_VIEW (self));
+
+  ide_source_view_movements_get_selection (self, &insert, &selection);
+
+  /* Move up to the first non-blank line */
+  while (gtk_text_iter_starts_line (&insert) &&
+         gtk_text_iter_ends_line (&insert))
+    if (!gtk_text_iter_backward_line (&insert))
+      break;
+
+  /* Find the next blank line */
+  while (gtk_text_iter_backward_line (&insert))
+    if (gtk_text_iter_starts_line (&insert) &&
+        gtk_text_iter_ends_line (&insert))
+      break;
+
+  ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
+static void
+ide_source_view_movements_paragraph_end (IdeSourceView         *self,
+                                        IdeSourceViewMovement  movement,
+                                        gboolean               extend_selection,
+                                        gint                   param)
+{
+  GtkTextIter insert;
+  GtkTextIter selection;
+
+  g_assert (IDE_IS_SOURCE_VIEW (self));
+
+  ide_source_view_movements_get_selection (self, &insert, &selection);
+
+  /* Move down to the first non-blank line */
+  while (gtk_text_iter_starts_line (&insert) && gtk_text_iter_ends_line (&insert))
+    if (!gtk_text_iter_forward_line (&insert))
+      break;
+
+  /* Find the next blank line */
+  while (gtk_text_iter_forward_line (&insert))
+    if (gtk_text_iter_starts_line (&insert) && gtk_text_iter_ends_line (&insert))
+      break;
+
+  ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
 void
 _ide_source_view_apply_movement (IdeSourceView         *self,
                                  IdeSourceViewMovement  movement,
@@ -860,9 +914,11 @@ _ide_source_view_apply_movement (IdeSourceView         *self,
       break;
 
     case IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_START:
+      ide_source_view_movements_paragraph_start (self, movement, extend_selection, param);
       break;
 
     case IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_END:
+      ide_source_view_movements_paragraph_end (self, movement, extend_selection, param);
       break;
 
     case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_LINE:


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