[gnome-builder] sourceview: use IdeSourceViewMovement for smart-home
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] sourceview: use IdeSourceViewMovement for smart-home
- Date: Wed, 22 Nov 2017 00:55:44 +0000 (UTC)
commit 2d89719b06f7b8685ce70dd2d045e4ddd31b8f27
Author: Christian Hergert <chergert redhat com>
Date: Tue Nov 21 16:42:49 2017 -0800
sourceview: use IdeSourceViewMovement for smart-home
This allows us to override the behavior of smart-home from
GtkSourceView so we have more control over the scrolling within
Builder and it's viewport.
https://bugzilla.gnome.org/show_bug.cgi?id=789947
src/libide/sourceview/ide-source-view-movements.c | 47 +++++++++++++++++++++
src/libide/sourceview/ide-source-view.c | 20 +++++++++
src/libide/sourceview/ide-source-view.h | 4 ++
3 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/src/libide/sourceview/ide-source-view-movements.c
b/src/libide/sourceview/ide-source-view-movements.c
index f4102a3..d5f2891 100644
--- a/src/libide/sourceview/ide-source-view-movements.c
+++ b/src/libide/sourceview/ide-source-view-movements.c
@@ -1931,6 +1931,41 @@ ide_source_view_movement_match_search_char (Movement *mv,
}
}
+static void
+ide_source_view_movements_smart_home (Movement *mv,
+ GtkSourceSmartHomeEndType mode)
+{
+ GtkTextIter iter;
+
+ g_assert (mv != NULL);
+
+ iter = mv->insert;
+
+ switch (mode)
+ {
+ case GTK_SOURCE_SMART_HOME_END_BEFORE:
+ ide_source_view_movements_first_nonspace_char (mv);
+ if (gtk_text_iter_equal (&iter, &mv->insert))
+ gtk_text_iter_set_line_offset (&mv->insert, 0);
+ return;
+
+ case GTK_SOURCE_SMART_HOME_END_AFTER:
+ ide_source_view_movements_first_char (mv);
+ if (gtk_text_iter_equal (&iter, &mv->insert))
+ ide_source_view_movements_first_nonspace_char (mv);
+ return;
+
+ case GTK_SOURCE_SMART_HOME_END_ALWAYS:
+ ide_source_view_movements_first_nonspace_char (mv);
+ return;
+
+ case GTK_SOURCE_SMART_HOME_END_DISABLED:
+ default:
+ ide_source_view_movements_first_char (mv);
+ return;
+ }
+}
+
void
_ide_source_view_apply_movement (IdeSourceView *self,
IdeSourceViewMovement movement,
@@ -2325,6 +2360,18 @@ _ide_source_view_apply_movement (IdeSourceView *self,
ide_source_view_movement_match_search_char (&mv, TRUE);
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_SMART_HOME:
+ {
+ GtkSourceSmartHomeEndType smart_home;
+
+ mv.count = 1;
+ mv.scroll_align = IDE_SOURCE_SCROLL_X;
+
+ smart_home = gtk_source_view_get_smart_home_end (GTK_SOURCE_VIEW (self));
+ ide_source_view_movements_smart_home (&mv, smart_home);
+ }
+ break;
+
default:
g_return_if_reached ();
}
diff --git a/src/libide/sourceview/ide-source-view.c b/src/libide/sourceview/ide-source-view.c
index 7c61578..8664793 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -6647,6 +6647,26 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
GDK_CONTROL_MASK | GDK_SHIFT_MASK,
"find-references", 0);
+ /* Override "Home" and "<Shift>Home" to use our movements
+ * instead of the smart home feature of GtkSourceView.
+ */
+ gtk_binding_entry_add_signal (binding_set,
+ GDK_KEY_Home,
+ 0,
+ "movement", 4,
+ IDE_TYPE_SOURCE_VIEW_MOVEMENT, IDE_SOURCE_VIEW_MOVEMENT_SMART_HOME,
+ G_TYPE_BOOLEAN, FALSE,
+ G_TYPE_BOOLEAN, TRUE,
+ G_TYPE_BOOLEAN, FALSE);
+ gtk_binding_entry_add_signal (binding_set,
+ GDK_KEY_Home,
+ GDK_MOD1_MASK | GDK_SHIFT_MASK,
+ "movement", 4,
+ IDE_TYPE_SOURCE_VIEW_MOVEMENT, IDE_SOURCE_VIEW_MOVEMENT_SMART_HOME,
+ G_TYPE_BOOLEAN, TRUE,
+ G_TYPE_BOOLEAN, TRUE,
+ G_TYPE_BOOLEAN, FALSE);
+
/*
* Escape is wired up by the GtkSourceCompletion by default. However, some
* keybindings may want to control that manually (such as Vim). Vim needs to
diff --git a/src/libide/sourceview/ide-source-view.h b/src/libide/sourceview/ide-source-view.h
index 9a11133..64884a3 100644
--- a/src/libide/sourceview/ide-source-view.h
+++ b/src/libide/sourceview/ide-source-view.h
@@ -129,6 +129,8 @@ typedef enum
* @IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_RIGHT: scroll until insert cursor or [count]th char is at screen
right.
* @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.
+ * @IDE_SOURCE_VIEW_MOVEMENT_SMART_HOME: Moves to the first non-whitespace character unless
+ * already positioned there. Otherwise, it moves to the first character.
*
* The type of movement.
*
@@ -224,6 +226,8 @@ typedef enum
IDE_SOURCE_VIEW_MOVEMENT_NEXT_MATCH_SEARCH_CHAR,
IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_MATCH_SEARCH_CHAR,
+
+ IDE_SOURCE_VIEW_MOVEMENT_SMART_HOME,
} IdeSourceViewMovement;
typedef enum
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]