[gtksourceview/wip/custom-word-boundaries-2: 5/5] view: override GtkTextView::delete-from-cursor



commit 33eead19552c1717cc5fc67f5710bee02cdd1ee3
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Dec 21 17:19:52 2014 +0100

    view: override GtkTextView::delete-from-cursor
    
    To use the custom word boundaries.

 gtksourceview/gtksourceview.c |   48 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 2717ece..4f01c4e 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -243,6 +243,9 @@ static void gtk_source_view_move_cursor             (GtkTextView        *text_view,
                                                         GtkMovementStep     step,
                                                         gint                count,
                                                         gboolean            extend_selection);
+static void    gtk_source_view_delete_from_cursor      (GtkTextView        *text_view,
+                                                        GtkDeleteType       type,
+                                                        gint                count);
 static gboolean gtk_source_view_extend_selection       (GtkTextView            *text_view,
                                                         GtkTextExtendSelection  granularity,
                                                         const GtkTextIter      *location,
@@ -332,6 +335,7 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
 
        textview_class->populate_popup = gtk_source_view_populate_popup;
        textview_class->move_cursor = gtk_source_view_move_cursor;
+       textview_class->delete_from_cursor = gtk_source_view_delete_from_cursor;
        textview_class->extend_selection = gtk_source_view_extend_selection;
        textview_class->create_buffer = gtk_source_view_create_buffer;
        textview_class->draw_layer = gtk_source_view_draw_layer;
@@ -1701,6 +1705,50 @@ gtk_source_view_move_cursor (GtkTextView    *text_view,
                                                                         extend_selection);
 }
 
+static void
+gtk_source_view_delete_from_cursor (GtkTextView   *text_view,
+                                   GtkDeleteType  type,
+                                   gint           count)
+{
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
+       GtkTextIter insert;
+       GtkTextIter start;
+       GtkTextIter end;
+
+       if (type != GTK_DELETE_WORD_ENDS)
+       {
+               GTK_TEXT_VIEW_CLASS (gtk_source_view_parent_class)->delete_from_cursor (text_view,
+                                                                                       type,
+                                                                                       count);
+               return;
+       }
+
+       gtk_text_buffer_get_iter_at_mark (buffer,
+                                         &insert,
+                                         gtk_text_buffer_get_insert (buffer));
+
+       start = insert;
+       end = insert;
+
+       if (count > 0)
+       {
+               if (!_gtk_source_iter_forward_visible_word_ends (&end, count))
+               {
+                       gtk_text_iter_forward_to_line_end (&end);
+               }
+       }
+       else
+       {
+               if (!_gtk_source_iter_backward_visible_word_starts (&start, -count))
+               {
+                       gtk_text_iter_set_line_offset (&start, 0);
+               }
+       }
+
+       gtk_text_buffer_delete_interactive (buffer, &start, &end,
+                                           gtk_text_view_get_editable (text_view));
+}
+
 static gboolean
 gtk_source_view_extend_selection (GtkTextView            *text_view,
                                  GtkTextExtendSelection  granularity,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]