@@ -819,7 +819,7 @@ bool TextEditInput::find(const char *word, bool next) {
819
819
break ;
820
820
}
821
821
}
822
-
822
+
823
823
if (_buf._buffer != NULL && word != NULL ) {
824
824
const char *found = find_str (allUpper, _buf._buffer + _state.cursor , word);
825
825
if (next && found != NULL ) {
@@ -1190,6 +1190,23 @@ void TextEditInput::editEnter() {
1190
1190
char spaces[LINE_BUFFER_SIZE];
1191
1191
int indent = getIndent (spaces, sizeof (spaces), prevLineStart);
1192
1192
if (indent) {
1193
+ // check whether the previous line was a comment
1194
+ if (prevLineStart) {
1195
+ char *buf = lineText (prevLineStart);
1196
+ int pos = 0 ;
1197
+ while (buf && (buf[pos] == ' ' || buf[pos] == ' \t ' )) {
1198
+ pos++;
1199
+ }
1200
+ if ((buf[pos] == ' #' || buf[pos] == ' \' ' ) && indent + 2 < LINE_BUFFER_SIZE) {
1201
+ spaces[indent] = buf[pos];
1202
+ spaces[++indent] = ' ' ;
1203
+ spaces[++indent] = ' \0 ' ;
1204
+ } else if (strncasecmp (buf + pos, " rem" , 3 ) == 0 ) {
1205
+ indent = strlcat (spaces, " rem " , LINE_BUFFER_SIZE);
1206
+ }
1207
+ free (buf);
1208
+ }
1209
+
1193
1210
_buf.insertChars (_state.cursor , spaces, indent);
1194
1211
stb_text_makeundo_insert (&_state, _state.cursor , indent);
1195
1212
_state.cursor += indent;
@@ -1199,7 +1216,6 @@ void TextEditInput::editEnter() {
1199
1216
1200
1217
void TextEditInput::editTab () {
1201
1218
char spaces[LINE_BUFFER_SIZE];
1202
- int indent;
1203
1219
1204
1220
// get the desired indent based on the previous line
1205
1221
int start = lineStart (_state.cursor );
@@ -1210,7 +1226,7 @@ void TextEditInput::editTab() {
1210
1226
prevLineStart = lineStart (prevLineStart - 1 );
1211
1227
}
1212
1228
// note - spaces not used in this context
1213
- indent = (prevLineStart || _cursorLine == 2 ) ? getIndent (spaces, sizeof (spaces), prevLineStart) : 0 ;
1229
+ int indent = (prevLineStart || _cursorLine == 2 ) ? getIndent (spaces, sizeof (spaces), prevLineStart) : 0 ;
1214
1230
1215
1231
// get the current lines indent
1216
1232
char *buf = lineText (start);
0 commit comments