[gnome-builder] libide: add movement for smart selection of line characters
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add movement for smart selection of line characters
- Date: Tue, 24 Mar 2015 00:01:33 +0000 (UTC)
commit 8ee2e9c319018e0fb28c4df56b7d49c7eb7c9bb6
Author: Christian Hergert <christian hergert me>
Date: Thu Mar 5 17:09:14 2015 -0800
libide: add movement for smart selection of line characters
This acts like the common behavior of vim when using ctrl+u during insert
mode. If you have a better name selection, i'm all ears.
libide/ide-source-view-movements.c | 44 ++++++++++++++++++++++++++++++++---
libide/ide-source-view.h | 5 ++++
2 files changed, 45 insertions(+), 4 deletions(-)
---
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index 6670091..66f76e4 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -209,12 +209,44 @@ ide_source_view_movements_first_nonspace_char (IdeSourceView *self,
g_unichar_isspace (ch))
gtk_text_iter_forward_char (&insert);
+ ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
+static void
+ide_source_view_movements_line_chars (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextIter insert;
+ GtkTextIter selection;
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
/*
- * if we are at the line end, there was only whitespace.
- * instead let's jump to the beginning of the line.
+ * Selects the current position up to the first nonspace character.
+ * If the cursor is at the line start, we will select the newline.
+ * If only whitespace exists, we will select line offset of 0.
*/
- if (gtk_text_iter_ends_line (&insert))
- gtk_text_iter_set_line_offset (&insert, 0);
+
+ if (gtk_text_iter_starts_line (&insert))
+ {
+ gtk_text_iter_backward_char (&insert);
+ }
+ else
+ {
+ gunichar ch;
+
+ gtk_text_iter_set_line_offset (&insert, 0);
+
+ while (!gtk_text_iter_ends_line (&insert) &&
+ (ch = gtk_text_iter_get_char (&insert)) &&
+ g_unichar_isspace (ch))
+ gtk_text_iter_forward_char (&insert);
+
+ if (gtk_text_iter_ends_line (&insert))
+ gtk_text_iter_set_line_offset (&insert, 0);
+ }
ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
}
@@ -1115,6 +1147,10 @@ _ide_source_view_apply_movement (IdeSourceView *self,
case IDE_SOURCE_VIEW_MOVEMENT_LINE_PERCENTAGE:
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_LINE_CHARS:
+ ide_source_view_movements_line_chars (self, movement, extend_selection, param);
+ break;
+
case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP:
case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN:
case IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP:
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index 8ca9397..ef91aa0 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -91,6 +91,9 @@ typedef enum
* @IDE_SOURCE_VIEW_MOVEMENT_LAST_LINE: move to last line in file, with line offset of zero.
* @IDE_SOURCE_VIEW_MOVEMENT_LINE_PERCENTAGE: move to line based on percentage. Use repeat to
* specify the percentage, 0 to 100.
+ * @IDE_SOURCE_VIEW_MOVEMENT_LINE_CHARS: special selection to select all line characters up to the
+ * cursor position. special care will be taken if the line is blank to select only the blank
+ * space if any. otherwise, the line break will be selected.
* @IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP: move half a page up.
* @IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN: move half a page down.
* @IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP: move a full page up.
@@ -146,6 +149,8 @@ typedef enum
IDE_SOURCE_VIEW_MOVEMENT_LAST_LINE,
IDE_SOURCE_VIEW_MOVEMENT_LINE_PERCENTAGE,
+ IDE_SOURCE_VIEW_MOVEMENT_LINE_CHARS,
+
IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP,
IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]