Kaydet (Commit) 381d74b1 authored tarafından Pavel Sountsov's avatar Pavel Sountsov Kaydeden (comit) SiegeLord

Use current selection when stripping trailing whitespace from the menu.

When the lines are stripped due to the file being saved, ignore the selection.
üst 31325bb2
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment