[geany/geany] 381d74: Use current selection when stripping trailing whitespace from the menu.

Pavel Sountsov git-noreply at xxxxx
Sun Aug 16 18:22:01 UTC 2015


Branch:      refs/heads/master
Author:      Pavel Sountsov <siege at google.com>
Committer:   SiegeLord <slabode at aim.com>
Date:        Sun, 16 Aug 2015 18:22:01 UTC
Commit:      381d74b1a72d5feef85fef56b25bb15d5403f955
             https://github.com/geany/geany/commit/381d74b1a72d5feef85fef56b25bb15d5403f955

Log Message:
-----------
Use current selection when stripping trailing whitespace from the menu.

When the lines are stripped due to the file being saved, ignore the selection.


Modified Paths:
--------------
    src/callbacks.c
    src/document.c
    src/editor.c
    src/editor.h

Modified: src/callbacks.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -1608,7 +1608,7 @@ static void on_strip_trailing_spaces1_activate(GtkMenuItem *menuitem, gpointer u
 	doc = document_get_current();
 	g_return_if_fail(doc != NULL);
 
-	editor_strip_trailing_spaces(doc->editor);
+	editor_strip_trailing_spaces(doc->editor, FALSE);
 }
 
 


Modified: src/document.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -2065,7 +2065,7 @@ gboolean document_save_file(GeanyDocument *doc, gboolean force)
 		editor_replace_tabs(doc->editor);
 	/* strip trailing spaces */
 	if (fp->strip_trailing_spaces)
-		editor_strip_trailing_spaces(doc->editor);
+		editor_strip_trailing_spaces(doc->editor, TRUE);
 	/* ensure the file has a newline at the end */
 	if (fp->final_new_line)
 		editor_ensure_final_newline(doc->editor);


Modified: src/editor.c
18 lines changed, 15 insertions(+), 3 deletions(-)
===================================================================
@@ -4429,14 +4429,26 @@ void editor_strip_line_trailing_spaces(GeanyEditor *editor, gint line)
 }
 
 
-void editor_strip_trailing_spaces(GeanyEditor *editor)
+void editor_strip_trailing_spaces(GeanyEditor *editor, gboolean ignore_selection)
 {
-	gint max_lines = sci_get_line_count(editor->sci);
+	gint start_line;
+	gint end_line;
 	gint line;
 
+	if (sci_has_selection(editor->sci) && !ignore_selection)
+	{
+		start_line = sci_get_line_from_position(editor->sci, sci_get_selection_start(editor->sci));
+		end_line = sci_get_line_from_position(editor->sci, sci_get_selection_end(editor->sci)) + 1;
+	}
+	else
+	{
+		start_line = 0;
+		end_line = sci_get_line_count(editor->sci);
+	}
+
 	sci_start_undo_action(editor->sci);
 
-	for (line = 0; line < max_lines; line++)
+	for (line = start_line; line < end_line; line++)
 	{
 		editor_strip_line_trailing_spaces(editor, line);
 	}


Modified: src/editor.h
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -301,7 +301,7 @@ void editor_replace_spaces(GeanyEditor *editor);
 
 void editor_strip_line_trailing_spaces(GeanyEditor *editor, gint line);
 
-void editor_strip_trailing_spaces(GeanyEditor *editor);
+void editor_strip_trailing_spaces(GeanyEditor *editor, gboolean ignore_selection);
 
 void editor_ensure_final_newline(GeanyEditor *editor);
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list