Use current selection when stripping trailing whitespace from the menu.
When the lines are stripped due to the file being saved, ignore the selection.
This commit is contained in:
parent
31325bb231
commit
381d74b1a7
@ -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);
|
||||
|
18
src/editor.c
18
src/editor.c
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user