[gtksourceview/wip/custom-word-boundaries-2: 1/2] view: override word boundaries for GtkTextView::move-cursor
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/custom-word-boundaries-2: 1/2] view: override word boundaries for GtkTextView::move-cursor
- Date: Sun, 21 Dec 2014 16:21:45 +0000 (UTC)
commit 4004824f3911ebc5b14232a4ad231fb464801bb1
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Dec 21 15:20:37 2014 +0100
view: override word boundaries for GtkTextView::move-cursor
gtksourceview/gtksourceview.c | 47 +++++++++++++++++++++++++++++++++++++---
1 files changed, 43 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 58d931a..ea3e86e 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -1379,15 +1379,18 @@ move_cursor (GtkTextView *text_view,
gboolean extend_selection)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
+ GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
if (extend_selection)
- gtk_text_buffer_move_mark_by_name (buffer, "insert",
- new_location);
+ {
+ gtk_text_buffer_move_mark (buffer, insert, new_location);
+ }
else
+ {
gtk_text_buffer_place_cursor (buffer, new_location);
+ }
- gtk_text_view_scroll_mark_onscreen (text_view,
- gtk_text_buffer_get_insert (buffer));
+ gtk_text_view_scroll_mark_onscreen (text_view, insert);
}
static void
@@ -1634,6 +1637,38 @@ move_cursor_smart_home_end (GtkTextView *text_view,
}
static void
+move_cursor_words (GtkTextView *text_view,
+ gint count,
+ gboolean extend_selection)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter insert;
+ GtkTextIter newplace;
+
+ buffer = gtk_text_view_get_buffer (text_view);
+
+ gtk_text_buffer_get_iter_at_mark (buffer,
+ &insert,
+ gtk_text_buffer_get_insert (buffer));
+
+ newplace = insert;
+
+ if (count < 0)
+ {
+ _gtk_source_iter_backward_visible_word_starts (&newplace, -count);
+ }
+ else if (count > 0)
+ {
+ if (!_gtk_source_iter_forward_visible_word_ends (&newplace, count))
+ {
+ gtk_text_iter_forward_to_line_end (&newplace);
+ }
+ }
+
+ move_cursor (text_view, &newplace, extend_selection);
+}
+
+static void
gtk_source_view_move_cursor (GtkTextView *text_view,
GtkMovementStep step,
gint count,
@@ -1649,6 +1684,10 @@ gtk_source_view_move_cursor (GtkTextView *text_view,
}
break;
+ case GTK_MOVEMENT_WORDS:
+ move_cursor_words (text_view, count, extend_selection);
+ return;
+
default:
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]