From 72c0ac8b27448de6cde76e1fbbb180a52f1003c7 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Fri, 19 Apr 2013 17:14:00 -0400 Subject: [PATCH] Added ability to not strip the current line This feature is good for the trim on save as usually an user do not want the line that they are currently selecting to be trimmed. --- mousepad/mousepad-view.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c index a123241..b03b153 100644 --- a/mousepad/mousepad-view.c +++ b/mousepad/mousepad-view.c @@ -820,7 +820,7 @@ mousepad_view_selection_draw (MousepadView *view, /* calculate line coordinates */ gtk_text_view_buffer_to_window_coords(textview,GTK_TEXT_WINDOW_TEXT, rect.x,rect.y, &line_x,&line_y); - + /* draw a line in front of the iter */ gdk_draw_line (GDK_DRAWABLE (window), gtk_widget_get_style(GTK_WIDGET (view))->base_gc[GTK_STATE_SELECTED], @@ -2030,8 +2030,9 @@ void mousepad_view_strip_trailing_spaces (MousepadView *view) { GtkTextBuffer *buffer; - GtkTextIter start_iter, end_iter, needle; - gint start, end, i; + GtkTextMark *mark; + GtkTextIter start_iter, end_iter, needle, current_iter; + gint start, end, i, current; gunichar c; mousepad_return_if_fail (MOUSEPAD_IS_VIEW (view)); @@ -2055,9 +2056,18 @@ mousepad_view_strip_trailing_spaces (MousepadView *view) g_object_freeze_notify (G_OBJECT (buffer)); gtk_text_buffer_begin_user_action (buffer); + /* get the current seleted line */ + mark = gtk_text_buffer_get_insert (buffer); + gtk_text_buffer_get_iter_at_mark (buffer, ¤t_iter, mark); + current = gtk_text_iter_get_line (¤t_iter); + /* walk all the selected lines */ for (i = start; i < end; i++) { + /* skip if the line is the current selected line. */ + if (i == current) + continue; + /* get the iter at the line */ gtk_text_buffer_get_iter_at_line (buffer, &end_iter, i); -- 1.7.9.5