[geany/geany] 624048: Keep selection stable when replacing tabs and spaces

Colomban Wendling git-noreply at xxxxx
Sun Aug 16 18:38:51 UTC 2015


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   SiegeLord <slabode at aim.com>
Date:        Sun, 16 Aug 2015 18:38:51 UTC
Commit:      624048ea5e731336097b6e0be5901b77aae075a8
             https://github.com/geany/geany/commit/624048ea5e731336097b6e0be5901b77aae075a8

Log Message:
-----------
Keep selection stable when replacing tabs and spaces


Modified Paths:
--------------
    src/editor.c

Modified: src/editor.c
18 lines changed, 18 insertions(+), 0 deletions(-)
===================================================================
@@ -4317,6 +4317,7 @@ void editor_fold_all(GeanyEditor *editor)
 void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection)
 {
 	gint search_pos, pos_in_line, current_tab_true_length;
+	gint anchor_pos, caret_pos;
 	gint tab_len;
 	gchar *tab_str;
 	struct Sci_TextToFind ttf;
@@ -4337,6 +4338,8 @@ void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection)
 	}
 	ttf.lpstrText = (gchar*) "\t";
 
+	anchor_pos = SSM(editor->sci, SCI_GETANCHOR, 0, 0);
+	caret_pos = sci_get_current_position(editor->sci);
 	while (TRUE)
 	{
 		search_pos = sci_find_text(editor->sci, SCFIND_MATCHCASE, &ttf);
@@ -4354,7 +4357,13 @@ void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection)
 		/* update end of range now text has changed */
 		ttf.chrg.cpMax += current_tab_true_length - 1;
 		g_free(tab_str);
+
+		if (anchor_pos > search_pos)
+			anchor_pos += current_tab_true_length - 1;
+		if (caret_pos > search_pos)
+			caret_pos += current_tab_true_length - 1;
 	}
+	sci_set_selection(editor->sci, anchor_pos, caret_pos);
 	sci_end_undo_action(editor->sci);
 }
 
@@ -4364,6 +4373,7 @@ void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection)
 void editor_replace_spaces(GeanyEditor *editor, gboolean ignore_selection)
 {
 	gint search_pos;
+	gint anchor_pos, caret_pos;
 	static gdouble tab_len_f = -1.0; /* keep the last used value */
 	gint tab_len;
 	gchar *text;
@@ -4397,6 +4407,8 @@ void editor_replace_spaces(GeanyEditor *editor, gboolean ignore_selection)
 	}
 	ttf.lpstrText = text;
 
+	anchor_pos = SSM(editor->sci, SCI_GETANCHOR, 0, 0);
+	caret_pos = sci_get_current_position(editor->sci);
 	while (TRUE)
 	{
 		search_pos = sci_find_text(editor->sci, SCFIND_MATCHCASE, &ttf);
@@ -4415,7 +4427,13 @@ void editor_replace_spaces(GeanyEditor *editor, gboolean ignore_selection)
 		ttf.chrg.cpMin = search_pos;
 		/* update end of range now text has changed */
 		ttf.chrg.cpMax -= tab_len - 1;
+
+		if (anchor_pos > search_pos)
+			anchor_pos -= tab_len - 1;
+		if (caret_pos > search_pos)
+			caret_pos -= tab_len - 1;
 	}
+	sci_set_selection(editor->sci, anchor_pos, caret_pos);
 	sci_end_undo_action(editor->sci);
 	g_free(text);
 }



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