[gnome-builder] source-view: improve handling of Control+BackSpace
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] source-view: improve handling of Control+BackSpace
- Date: Fri, 8 May 2015 19:23:08 +0000 (UTC)
commit 7657001a178a68dab5e194cbf6fac5e1f2960861
Author: Christian Hergert <christian hergert me>
Date: Fri May 8 12:19:45 2015 -0700
source-view: improve handling of Control+BackSpace
GtkTextView universally sucks at handling Control+BackSpace. It is
non-obvious where the backspace will end and often jumps multiple lines.
As such, we will override that behavior when smart-backspace is emabled.
If you are at the beginning of a line, ctrl+backspace will simply move
you to the end of the previous line. I believe this is the right
behavior because anything else would require you to be cross-eyed and
looking at the start and end of the line at the same time. Non-obvious.
When there is only whitespace between the insertion cursor and the
beginning of the line, we will remove that space and leave the insert
mark at line offset 0.
libide/ide-source-view.c | 37 ++++++++++++++++++++++++++++++++++---
1 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 2077b0e..2e000dc 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -1915,15 +1915,33 @@ ide_source_view_do_smart_backspace (IdeSourceView *self,
g_assert (event);
g_assert (event->type == GDK_KEY_PRESS);
-#define GET_VISUAL_COLUMN(iter) gtk_source_view_get_visual_column(GTK_SOURCE_VIEW(self),iter)
-
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
- gtk_text_buffer_get_selection_bounds (buffer, &insert, &end);
+ ide_buffer_get_selection_bounds (IDE_BUFFER (buffer), &insert, &end);
if (!gtk_text_iter_equal (&insert, &end))
IDE_RETURN (FALSE);
+ if ((event->state & GDK_CONTROL_MASK) != 0)
+ {
+ /*
+ * A <Control>BackSpace at the beginning of the line should only move us to the
+ * end of the previous line. Anything more than that is non-obvious because it requires
+ * looking in a position other than where the cursor is.
+ */
+ if ((gtk_text_iter_get_line_offset (&insert) == 0) && (gtk_text_iter_get_line (&insert) > 0))
+ {
+ gtk_text_buffer_begin_user_action (buffer);
+ gtk_text_iter_backward_char (&insert);
+ gtk_text_buffer_delete (buffer, &insert, &end);
+ gtk_text_buffer_end_user_action (buffer);
+
+ IDE_RETURN (TRUE);
+ }
+ }
+
+#define GET_VISUAL_COLUMN(iter) gtk_source_view_get_visual_column(GTK_SOURCE_VIEW(self),iter)
+
/* if the line isn't empty up to our cursor, ignore */
tmp = insert;
while (TRUE)
@@ -1941,6 +1959,19 @@ ide_source_view_do_smart_backspace (IdeSourceView *self,
gtk_text_iter_backward_char (&tmp);
}
+ /*
+ * If <Control>BackSpace was specified, delete up to the zero position.
+ */
+ if ((event->state & GDK_CONTROL_MASK) != 0)
+ {
+ gtk_text_buffer_begin_user_action (buffer);
+ gtk_text_iter_set_line_offset (&insert, 0);
+ gtk_text_buffer_delete (buffer, &insert, &end);
+ gtk_text_buffer_end_user_action (buffer);
+
+ IDE_RETURN (TRUE);
+ }
+
visual_column = GET_VISUAL_COLUMN (&insert);
indent_width = gtk_source_view_get_indent_width (GTK_SOURCE_VIEW (self));
tab_width = gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]