From 5a53a705a5c2b495411c483b7a16acf49472fa94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nelson=20Ben=C3=ADtez=20Le=C3=B3n?=
 <nbenitezl+gnome@gmail.com>
Date: Wed, 28 Jun 2017 16:59:31 +0100
Subject: [PATCH] gtksourceview.c: support new GtkTextView rectangular mode
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

· Free Alt shorcut to be used for GtkTextView rectangular mode,
use Ctrl+Alt instead for move-lines.

· Ignore auto-indent when pressing ENTER if we're in rect mode.

· Let Tab key bubble up to GtkTextView when in rect mode, so it
can be handled properly.
---
 gtksourceview/gtksourceview.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 61904404..67a8e67a 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -941,46 +941,46 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
 
 	gtk_binding_entry_add_signal (binding_set,
 				      GDK_KEY_Up,
-				      GDK_MOD1_MASK,
+				      GDK_MOD1_MASK | GDK_CONTROL_MASK,
 				      "move-lines", 2,
 				      G_TYPE_BOOLEAN, FALSE,
 				      G_TYPE_INT, -1);
 	gtk_binding_entry_add_signal (binding_set,
 				      GDK_KEY_KP_Up,
-				      GDK_MOD1_MASK,
+				      GDK_MOD1_MASK | GDK_CONTROL_MASK,
 				      "move-lines", 2,
 				      G_TYPE_BOOLEAN, FALSE,
 				      G_TYPE_INT, -1);
 	gtk_binding_entry_add_signal (binding_set,
 				      GDK_KEY_Down,
-				      GDK_MOD1_MASK,
+				      GDK_MOD1_MASK | GDK_CONTROL_MASK,
 				      "move-lines", 2,
 				      G_TYPE_BOOLEAN, FALSE,
 				      G_TYPE_INT, 1);
 	gtk_binding_entry_add_signal (binding_set,
 				      GDK_KEY_KP_Down,
-				      GDK_MOD1_MASK,
+				      GDK_MOD1_MASK | GDK_CONTROL_MASK,
 				      "move-lines", 2,
 				      G_TYPE_BOOLEAN, FALSE,
 				      G_TYPE_INT, 1);
 
 	gtk_binding_entry_add_signal (binding_set,
 				      GDK_KEY_Left,
-				      GDK_MOD1_MASK,
+				      GDK_MOD1_MASK | GDK_CONTROL_MASK,
 				      "move-words", 1,
 				      G_TYPE_INT, -1);
 	gtk_binding_entry_add_signal (binding_set,
-				      GDK_KEY_KP_Left,
+				      GDK_KEY_KP_Left | GDK_CONTROL_MASK,
 				      GDK_MOD1_MASK,
 				      "move-words", 1,
 				      G_TYPE_INT, -1);
 	gtk_binding_entry_add_signal (binding_set,
-				      GDK_KEY_Right,
+				      GDK_KEY_Right | GDK_CONTROL_MASK,
 				      GDK_MOD1_MASK,
 				      "move-words", 1,
 				      G_TYPE_INT, 1);
 	gtk_binding_entry_add_signal (binding_set,
-				      GDK_KEY_KP_Right,
+				      GDK_KEY_KP_Right | GDK_CONTROL_MASK,
 				      GDK_MOD1_MASK,
 				      "move-words", 1,
 				      G_TYPE_INT, 1);
@@ -4027,11 +4027,13 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
 	guint modifiers;
 	gint key;
 	gboolean editable;
+	gboolean rect_mode;
 
 	view = GTK_SOURCE_VIEW (widget);
 	buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
 
 	editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (widget));
+	rect_mode = gtk_text_buffer_get_rect_mode (buf);
 
 	/* Be careful when testing for modifier state equality:
 	 * caps lock, num lock,etc need to be taken into account */
@@ -4044,7 +4046,7 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
 
 	if ((key == GDK_KEY_Return || key == GDK_KEY_KP_Enter) &&
 	    !(event->state & GDK_SHIFT_MASK) &&
-	    view->priv->auto_indent)
+	    view->priv->auto_indent && !rect_mode)
 	{
 		/* Auto-indent means that when you press ENTER at the end of a
 		 * line, the new line is automatically indented at the same
@@ -4085,11 +4087,12 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
 
 	/* if tab or shift+tab:
 	 * with shift+tab key is GDK_ISO_Left_Tab (yay! on win32 and mac too!)
+	 * Don't handle tab in rectangular sel mode, so can reach GtkTextView to be handled properly
 	 */
 	if ((key == GDK_KEY_Tab || key == GDK_KEY_KP_Tab || key == GDK_KEY_ISO_Left_Tab) &&
 	    ((event->state & modifiers) == 0 ||
 	     (event->state & modifiers) == GDK_SHIFT_MASK) &&
-	    editable)
+	    editable && !rect_mode)
 	{
 		GtkTextIter s, e;
 		gboolean has_selection;
-- 
2.13.0

