Skip to content

Commit ef39179

Browse files
committed
UI: fix tab indent
1 parent 989524b commit ef39179

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

src/ui/textedit.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,19 +1008,8 @@ void TextEditInput::editTab() {
10081008
}
10091009

10101010
// adjust indent for statement terminators
1011-
if (strncasecmp(buf + curIndent, "wend", 4) == 0 ||
1012-
strncasecmp(buf + curIndent, "fi", 2) == 0 ||
1013-
strncasecmp(buf + curIndent, "endif", 5) == 0 ||
1014-
strncasecmp(buf + curIndent, "elseif ", 7) == 0 ||
1015-
strncasecmp(buf + curIndent, "elif ", 5) == 0 ||
1016-
strncasecmp(buf + curIndent, "else", 4) == 0 ||
1017-
strncasecmp(buf + curIndent, "next", 4) == 0 ||
1018-
strncasecmp(buf + curIndent, "case", 4) == 0 ||
1019-
strncasecmp(buf + curIndent, "end", 3) == 0 ||
1020-
strncasecmp(buf + curIndent, "until ", 6) == 0) {
1021-
if (indent >= _indentLevel) {
1022-
indent -= _indentLevel;
1023-
}
1011+
if (indent >= _indentLevel && endStatement(buf + curIndent)) {
1012+
indent -= _indentLevel;
10241013
}
10251014
if (curIndent < indent) {
10261015
// insert additional spaces
@@ -1054,6 +1043,35 @@ void TextEditInput::editTab() {
10541043
free(buf);
10551044
}
10561045

1046+
bool TextEditInput::endStatement(const char *buf) {
1047+
const struct Holder {
1048+
const char *symbol;
1049+
int len;
1050+
} term[] = {
1051+
{"wend", 4},
1052+
{"fi", 2},
1053+
{"endif", 5},
1054+
{"elseif ", 7},
1055+
{"elif ", 5},
1056+
{"else", 4},
1057+
{"next", 4},
1058+
{"case", 4},
1059+
{"end", 3},
1060+
{"until ", 6}
1061+
};
1062+
const int len = sizeof(term) / sizeof(Holder);
1063+
bool result = false;
1064+
for (int i = 0; i < len && !result; i++) {
1065+
if (strncasecmp(buf, term[i].symbol, term[i].len) == 0) {
1066+
char c = buf[term[i].len];
1067+
if (c == '\0' || IS_WHITE(c)) {
1068+
result = true;
1069+
}
1070+
}
1071+
}
1072+
return result;
1073+
}
1074+
10571075
void TextEditInput::findMatchingBrace() {
10581076
char cursorChar = _state.cursor < _buf._len ? _buf._buffer[_state.cursor] : '\0';
10591077
char cursorMatch = '\0';

src/ui/textedit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct TextEditInput : public FormEditInput {
131131
void editDeleteLine();
132132
void editEnter();
133133
void editTab();
134+
bool endStatement(const char *buf);
134135
void findMatchingBrace();
135136
int getCursorRow() const;
136137
uint32_t getHash(const char *str, int offs, int &count);

0 commit comments

Comments
 (0)