[PATCH] Added ability to not strip the current line
Shuhao
shuhao at shuhaowu.com
Fri Apr 19 23:20:09 CEST 2013
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
More information about the Xfce4-dev
mailing list