forked from bartvdbraak/blender
patch [#23088] 2.5 Text Editor: Preserve indentation with spaces
from Fabian Fricke (frigi)
This commit is contained in:
parent
c1fd3ae7a0
commit
b1f53d98e4
@ -92,7 +92,7 @@ void unindent (struct Text *text);
|
||||
void comment (struct Text *text);
|
||||
void indent (struct Text *text);
|
||||
void uncomment (struct Text *text);
|
||||
int setcurr_tab (struct Text *text);
|
||||
int setcurr_tab_spaces (struct Text *text, int space);
|
||||
|
||||
void txt_add_marker (struct Text *text, struct TextLine *line, int start, int end, char color[4], int group, int flags);
|
||||
short txt_clear_marker_region (struct Text *text, struct TextLine *line, int start, int end, int group, int flags);
|
||||
|
@ -2683,19 +2683,20 @@ void uncomment(Text *text)
|
||||
}
|
||||
}
|
||||
|
||||
int setcurr_tab (Text *text)
|
||||
int setcurr_tab_spaces (Text *text, int space)
|
||||
{
|
||||
int i = 0;
|
||||
int test = 0;
|
||||
char *word = ":";
|
||||
char *comm = "#";
|
||||
const char *word = ":";
|
||||
const char *comm = "#";
|
||||
const char indent= (text->flags & TXT_TABSTOSPACES) ? ' ' : '\t';
|
||||
static char *back_words[]= {"return", "break", "continue", "pass", "yield", NULL};
|
||||
if (!text) return 0;
|
||||
if (!text->curl) return 0;
|
||||
|
||||
while (text->curl->line[i] == '\t')
|
||||
while (text->curl->line[i] == indent)
|
||||
{
|
||||
//we only count thos tabs that are before any text or before the curs;
|
||||
//we only count those tabs/spaces that are before any text or before the curs;
|
||||
if (i == text->curc)
|
||||
{
|
||||
return i;
|
||||
@ -2718,7 +2719,7 @@ int setcurr_tab (Text *text)
|
||||
}
|
||||
}
|
||||
if (indent) {
|
||||
i++;
|
||||
i += space;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2729,7 +2730,7 @@ int setcurr_tab (Text *text)
|
||||
{
|
||||
if(strcspn(text->curl->line, back_words[test]) < strcspn(text->curl->line, comm))
|
||||
{
|
||||
i--;
|
||||
i -= space;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -902,15 +902,22 @@ void TEXT_OT_unindent(wmOperatorType *ot)
|
||||
|
||||
static int line_break_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
SpaceText *st= CTX_wm_space_text(C);
|
||||
Text *text= CTX_data_edit_text(C);
|
||||
int a, curtab;
|
||||
int a, curts;
|
||||
int space = (text->flags & TXT_TABSTOSPACES) ? st->tabnumber : 1;
|
||||
|
||||
// double check tabs before splitting the line
|
||||
curtab= setcurr_tab(text);
|
||||
// double check tabs/spaces before splitting the line
|
||||
curts= setcurr_tab_spaces(text, space);
|
||||
txt_split_curline(text);
|
||||
|
||||
for(a=0; a < curtab; a++)
|
||||
for(a=0; a < curts; a++) {
|
||||
if (text->flags & TXT_TABSTOSPACES) {
|
||||
txt_add_char(text, ' ');
|
||||
} else {
|
||||
txt_add_char(text, '\t');
|
||||
}
|
||||
}
|
||||
|
||||
if(text->curl) {
|
||||
if(text->curl->prev)
|
||||
|
Loading…
Reference in New Issue
Block a user