Removed unnecessary code in document_replace_tabs().

Really take tab width when replacing instead of using width = 4.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@705 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2006-08-12 16:24:29 +00:00
parent a830f3326f
commit d7dcd5474c
2 changed files with 10 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2006-08-12 Enrico Tröger <enrico.troeger@uvena.de>
* src/document.c:
Removed unnecessary code in document_replace_tabs().
Really take tab width when replacing instead of using width = 4.
2006-08-12 Nick Treleaven <nick.treleaven@btinternet.com> 2006-08-12 Nick Treleaven <nick.treleaven@btinternet.com>
* src/search.c: Enable case sensitive when regex search enabled. * src/search.c: Enable case sensitive when regex search enabled.

View File

@ -1308,31 +1308,25 @@ void document_print(gint idx)
void document_replace_tabs(gint idx) void document_replace_tabs(gint idx)
{ {
gint i, len, j = 0, tabs_amount = 0, tab_w, pos; gint i, len, j = 0, k, tabs_amount = 0, tab_w, pos;
gchar *data, *replacement, *text; gchar *data, *text;
if (idx < 0 || ! doc_list[idx].is_valid) return; if (idx < 0 || ! doc_list[idx].is_valid) return;
pos = sci_get_current_position(doc_list[idx].sci); pos = sci_get_current_position(doc_list[idx].sci);
tab_w = sci_get_tab_width(doc_list[idx].sci); tab_w = sci_get_tab_width(doc_list[idx].sci);
replacement = g_malloc(tab_w + 1);
// get the text // get the text
len = sci_get_length(doc_list[idx].sci) + 1; len = sci_get_length(doc_list[idx].sci) + 1;
data = g_malloc(len); data = g_malloc(len);
sci_get_text(doc_list[idx].sci, len, data); sci_get_text(doc_list[idx].sci, len, data);
// prepare the spaces with the width of a tab
for (i = 0; i < tab_w; i++) replacement[i] = ' ';
replacement[tab_w] = '\0';
for (i = 0; i < len; i++) if (data[i] == 9) tabs_amount++; for (i = 0; i < len; i++) if (data[i] == 9) tabs_amount++;
// if there are no tabs, just return and leave the content untouched // if there are no tabs, just return and leave the content untouched
if (tabs_amount == 0) if (tabs_amount == 0)
{ {
g_free(data); g_free(data);
g_free(replacement);
return; return;
} }
@ -1345,10 +1339,7 @@ void document_replace_tabs(gint idx)
// increase cursor position to keep it at same position // increase cursor position to keep it at same position
if (pos > i) pos += 3; if (pos > i) pos += 3;
text[j++] = 32; for (k = 0; k < tab_w; k++) text[j++] = 32;
text[j++] = 32;
text[j++] = 32;
text[j++] = 32;
} }
else else
{ {
@ -1363,7 +1354,6 @@ void document_replace_tabs(gint idx)
g_free(data); g_free(data);
g_free(text); g_free(text);
g_free(replacement);
} }