Skip to content

Commit 2994204

Browse files
committed
UI: Edit enter now continues prior line comment
1 parent 3d44b93 commit 2994204

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2019-02-02 (0.12.15)
2+
UI: Edit enter now continues prior line comment
3+
14
2019-01-21 (0.12.15.1)
25
ANDROID: fix setup screen colour display
36
ANDROID: show link to android page in about

src/ui/textedit.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ bool TextEditInput::find(const char *word, bool next) {
819819
break;
820820
}
821821
}
822-
822+
823823
if (_buf._buffer != NULL && word != NULL) {
824824
const char *found = find_str(allUpper, _buf._buffer + _state.cursor, word);
825825
if (next && found != NULL) {
@@ -1190,6 +1190,23 @@ void TextEditInput::editEnter() {
11901190
char spaces[LINE_BUFFER_SIZE];
11911191
int indent = getIndent(spaces, sizeof(spaces), prevLineStart);
11921192
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+
11931210
_buf.insertChars(_state.cursor, spaces, indent);
11941211
stb_text_makeundo_insert(&_state, _state.cursor, indent);
11951212
_state.cursor += indent;
@@ -1199,7 +1216,6 @@ void TextEditInput::editEnter() {
11991216

12001217
void TextEditInput::editTab() {
12011218
char spaces[LINE_BUFFER_SIZE];
1202-
int indent;
12031219

12041220
// get the desired indent based on the previous line
12051221
int start = lineStart(_state.cursor);
@@ -1210,7 +1226,7 @@ void TextEditInput::editTab() {
12101226
prevLineStart = lineStart(prevLineStart - 1);
12111227
}
12121228
// 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;
12141230

12151231
// get the current lines indent
12161232
char *buf = lineText(start);

0 commit comments

Comments
 (0)