@@ -973,7 +973,8 @@ void TextEditInput::editEnter() {
973
973
char spaces[LINE_BUFFER_SIZE];
974
974
int start = lineStart (_state.cursor );
975
975
int prevLineStart = lineStart (start - 1 );
976
- if (prevLineStart >= 0 ) {
976
+
977
+ if (prevLineStart || _cursorLine == 1 ) {
977
978
int indent = getIndent (spaces, sizeof (spaces), prevLineStart);
978
979
if (indent) {
979
980
_buf.insertChars (_state.cursor , spaces, indent);
@@ -996,7 +997,7 @@ void TextEditInput::editTab() {
996
997
prevLineStart = lineStart (prevLineStart - 1 );
997
998
}
998
999
// note - spaces not used in this context
999
- indent = prevLineStart == 0 ? 0 : getIndent (spaces, sizeof (spaces), prevLineStart);
1000
+ indent = ( prevLineStart || _cursorLine == 2 ) ? getIndent (spaces, sizeof (spaces), prevLineStart) : 0 ;
1000
1001
1001
1002
// get the current lines indent
1002
1003
char *buf = lineText (start);
@@ -1176,7 +1177,7 @@ int TextEditInput::getIndent(char *spaces, int len, int pos) {
1176
1177
// count the indent level and find the start of text
1177
1178
char *buf = lineText (pos);
1178
1179
int i = 0 ;
1179
- while (buf && buf[i] == ' ' && i < len) {
1180
+ while (buf && ( buf[i] == ' ' || buf[i] == ' \t ' ) && i < len) {
1180
1181
spaces[i] = buf[i];
1181
1182
i++;
1182
1183
}
@@ -1205,7 +1206,7 @@ int TextEditInput::getIndent(char *spaces, int len, int pos) {
1205
1206
j++;
1206
1207
}
1207
1208
// right trim trailing spaces
1208
- while (buf[j - 1 ] == ' ' && j > i) {
1209
+ while (( buf[j - 1 ] == ' ' || buf[j - 1 ] == ' \t ' ) && j > i) {
1209
1210
j--;
1210
1211
}
1211
1212
if (strncasecmp (buf + j - 4 , " then" , 4 ) != 0 ) {
0 commit comments