[geany/geany] 795230: Use current selection when replacing tabs/spaces 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:      795230c5728a5d91c57d989c5356460dd5209854
             https://github.com/geany/geany/commit/795230c5728a5d91c57d989c5356460dd5209854

Log Message:
-----------
Use current selection when replacing tabs/spaces from the menu.

When saving the file, the tabs are removed from the whole file as usual.


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

Modified: src/callbacks.c
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -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);
 }
 
 


Modified: src/document.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -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);


Modified: src/editor.c
31 lines changed, 24 insertions(+), 7 deletions(-)
===================================================================
@@ -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)


Modified: src/editor.h
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -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);
 



--------------
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