Index: text.c =================================================================== --- text.c (revision 51595) +++ text.c (working copy) @@ -2834,7 +2834,7 @@ void txt_indent(Text *text) { - int len, num; + int len, num, curc_old; char *tmp; const char *add = "\t"; @@ -2856,6 +2856,8 @@ add = tab_to_spaces; indentlen = spaceslen; } + + curc_old = text->curc; num = 0; while (TRUE) { @@ -2877,7 +2879,8 @@ txt_clean_text(text); if (text->curl == text->sell) { - text->selc = text->sell->len; + text->selc += indentlen; + //text->selc = text->sell->len; break; } else { @@ -2885,7 +2888,8 @@ num++; } } - text->curc = 0; + //text->curc = 0; + text->curc = curc_old + indentlen; while (num > 0) { text->curl = text->curl->prev; num--; @@ -2900,7 +2904,8 @@ { int num = 0; const char *remove = "\t"; - int indent = 1; + int indentlen = 1; + int unindented_first = FALSE; /* hardcoded: TXT_TABSIZE = 4 spaces: */ int spaceslen = TXT_TABSIZE; @@ -2912,25 +2917,27 @@ /* insert spaces rather than tabs */ if (text->flags & TXT_TABSTOSPACES) { remove = tab_to_spaces; - indent = spaceslen; + indentlen = spaceslen; } - + while (TRUE) { - int i = 0; + int i = 0; - if (BLI_strncasecmp(text->curl->line, remove, indent) == 0) { + if (BLI_strncasecmp(text->curl->line, remove, indentlen) == 0) { + if (num == 0) unindented_first = TRUE; while (i < text->curl->len) { - text->curl->line[i] = text->curl->line[i + indent]; + text->curl->line[i] = text->curl->line[i + indentlen]; i++; } - text->curl->len -= indent; + text->curl->len -= indentlen; } - + txt_make_dirty(text); txt_clean_text(text); if (text->curl == text->sell) { - text->selc = text->sell->len; + //text->selc = text->sell->len; + if (i > 0) text->selc -= indentlen; break; } else { @@ -2939,7 +2946,10 @@ } } - text->curc = 0; + + //text->curc = 0; + if (unindented_first) text->curc -= indentlen; + while (num > 0) { text->curl = text->curl->prev; num--;