Use current selection when replacing tabs/spaces from the menu.

When saving the file, the tabs are removed from the whole file as usual.
This commit is contained in:
Pavel Sountsov 2014-12-25 12:23:09 -08:00 committed by SiegeLord
parent 381d74b1a7
commit 795230c572
4 changed files with 29 additions and 12 deletions

View File

@ -536,7 +536,7 @@ void on_replace_tabs_activate(GtkMenuItem *menuitem, gpointer user_data)
g_return_if_fail(doc != NULL);
editor_replace_tabs(doc->editor);
editor_replace_tabs(doc->editor, FALSE);
}
@ -1652,7 +1652,7 @@ void on_replace_spaces_activate(GtkMenuItem *menuitem, gpointer user_data)
g_return_if_fail(doc != NULL);
editor_replace_spaces(doc->editor);
editor_replace_spaces(doc->editor, FALSE);
}

View File

@ -2062,7 +2062,7 @@ gboolean document_save_file(GeanyDocument *doc, gboolean force)
fp = project_get_file_prefs();
/* replaces tabs with spaces but only if the current file is not a Makefile */
if (fp->replace_tabs && doc->file_type->id != GEANY_FILETYPES_MAKE)
editor_replace_tabs(doc->editor);
editor_replace_tabs(doc->editor, TRUE);
/* strip trailing spaces */
if (fp->strip_trailing_spaces)
editor_strip_trailing_spaces(doc->editor, TRUE);

View File

@ -4314,7 +4314,7 @@ void editor_fold_all(GeanyEditor *editor)
}
void editor_replace_tabs(GeanyEditor *editor)
void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection)
{
gint search_pos, pos_in_line, current_tab_true_length;
gint tab_len;
@ -4325,8 +4325,16 @@ void editor_replace_tabs(GeanyEditor *editor)
sci_start_undo_action(editor->sci);
tab_len = sci_get_tab_width(editor->sci);
ttf.chrg.cpMin = 0;
ttf.chrg.cpMax = sci_get_length(editor->sci);
if (sci_has_selection(editor->sci) && !ignore_selection)
{
ttf.chrg.cpMin = sci_get_selection_start(editor->sci);
ttf.chrg.cpMax = sci_get_selection_end(editor->sci);
}
else
{
ttf.chrg.cpMin = 0;
ttf.chrg.cpMax = sci_get_length(editor->sci);
}
ttf.lpstrText = (gchar*) "\t";
while (TRUE)
@ -4351,8 +4359,9 @@ void editor_replace_tabs(GeanyEditor *editor)
}
/* Replaces all occurrences all spaces of the length of a given tab_width. */
void editor_replace_spaces(GeanyEditor *editor)
/* Replaces all occurrences all spaces of the length of a given tab_width,
* optionally restricting the search to the current selection. */
void editor_replace_spaces(GeanyEditor *editor, gboolean ignore_selection)
{
gint search_pos;
static gdouble tab_len_f = -1.0; /* keep the last used value */
@ -4376,8 +4385,16 @@ void editor_replace_spaces(GeanyEditor *editor)
text = g_strnfill(tab_len, ' ');
sci_start_undo_action(editor->sci);
ttf.chrg.cpMin = 0;
ttf.chrg.cpMax = sci_get_length(editor->sci);
if (sci_has_selection(editor->sci) && !ignore_selection)
{
ttf.chrg.cpMin = sci_get_selection_start(editor->sci);
ttf.chrg.cpMax = sci_get_selection_end(editor->sci);
}
else
{
ttf.chrg.cpMin = 0;
ttf.chrg.cpMax = sci_get_length(editor->sci);
}
ttf.lpstrText = text;
while (TRUE)

View File

@ -295,9 +295,9 @@ void editor_fold_all(GeanyEditor *editor);
void editor_unfold_all(GeanyEditor *editor);
void editor_replace_tabs(GeanyEditor *editor);
void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection);
void editor_replace_spaces(GeanyEditor *editor);
void editor_replace_spaces(GeanyEditor *editor, gboolean ignore_selection);
void editor_strip_line_trailing_spaces(GeanyEditor *editor, gint line);