Skip to content

Commit 4f52c96

Browse files
committed
UI: add highlighting for digits
1 parent 1d2e2ea commit 4f52c96

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/ui/textedit.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@
2828
int g_themeId = 0;
2929

3030
const int theme1[] = {
31-
0xffffff, 0xa7aebc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
31+
0xc8cedb, 0xa7aebc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
3232
0x272b33, 0x3d4350, 0x2b3039, 0x3875ed, 0x373b88, 0x2b313a,
33-
0x0083f8, 0xff9d00, 0x31ccac
33+
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd
3434
};
3535

3636
const int theme2[] = {
37-
0xffffff, 0x002b36, 0x3d4350, 0xa7aebc, 0xa7aebc, 0x00bb00,
37+
0xc8cedb, 0x002b36, 0x3d4350, 0xa7aebc, 0xa7aebc, 0x00bb00,
3838
0x002b36, 0x657b83, 0x073642, 0x9f7d18, 0x2b313a, 0x073642,
39-
0x0083f8, 0xff9d00, 0x31ccac
39+
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd
4040
};
4141

4242
const int theme3[] = {
43-
0xffffff, 0xd7decc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
43+
0xc8cedb, 0xd7decc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
4444
0x001b33, 0x0088ff, 0x000d1a, 0x0051b1, 0x373b88, 0x022444,
45-
0x0083f8, 0xff9d00, 0x31ccac
45+
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd
4646
};
4747

4848
const int theme4[] = {
49-
0xffffff, 0xa7aebc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
49+
0xc8cedb, 0xa7aebc, 0x484f5f, 0xa7aebc, 0xa7aebc, 0x00bb00,
5050
0x2e3436, 0x888a85, 0x000000, 0x4d483b, 0x000000, 0x2b313a,
51-
0x0083f8, 0xff9d00, 0x31ccac
51+
0x0083f8, 0xff9d00, 0x31ccac, 0xc679dd
5252
};
5353

5454
const int* themes[] = {
@@ -115,7 +115,8 @@ EditTheme::EditTheme(int fg, int bg) :
115115
_syntax_comments(bg),
116116
_syntax_text(fg),
117117
_syntax_command(fg),
118-
_syntax_statement(fg) {
118+
_syntax_statement(fg),
119+
_syntax_digit(fg) {
119120
}
120121

121122
void EditTheme::selectTheme(const int theme[]) {
@@ -134,6 +135,7 @@ void EditTheme::selectTheme(const int theme[]) {
134135
_syntax_text = theme[12];
135136
_syntax_command = theme[13];
136137
_syntax_statement = theme[14];
138+
_syntax_digit = theme[15];
137139
}
138140

139141
//
@@ -434,7 +436,9 @@ void TextEditInput::drawText(int x, int y, const char *str,
434436
next = length - i;
435437
nextState = kComment;
436438
break;
437-
} else if (state == kReset && str[i] == '\"') {
439+
} else if (state != kReset) {
440+
break;
441+
} else if (str[i] == '\"') {
438442
next = 1;
439443
while (i + next < length && str[i + next] != '\"') {
440444
next++;
@@ -444,7 +448,18 @@ void TextEditInput::drawText(int x, int y, const char *str,
444448
}
445449
nextState = kText;
446450
break;
447-
} else if (state == kReset) {
451+
} else if (isdigit(str[i]) && (i == 0 || !isalpha(str[i - 1]))) {
452+
next = 1;
453+
while (i + next < length && isdigit(str[i + next])) {
454+
next++;
455+
}
456+
if (i > 0 && str[i - 1] == '.') {
457+
count--;
458+
next++;
459+
}
460+
nextState = kDigit;
461+
break;
462+
} else {
448463
int size = 0;
449464
uint32_t hash = getHash(str, i, size);
450465
if (hash > 0) {
@@ -1190,6 +1205,7 @@ void TextEditInput::pageNavigate(bool pageDown, bool shift) {
11901205
} else {
11911206
_state.select_start = _state.select_end;
11921207
}
1208+
11931209
_state.cursor = i;
11941210
_cursorRow = row;
11951211
updateScroll();
@@ -1215,6 +1231,9 @@ void TextEditInput::setColor(SyntaxState &state) {
12151231
case kStatement:
12161232
maSetColor(_theme->_syntax_statement);
12171233
break;
1234+
case kDigit:
1235+
maSetColor(_theme->_syntax_digit);
1236+
break;
12181237
case kReset:
12191238
maSetColor(_theme->_color);
12201239
break;
@@ -1225,7 +1244,7 @@ void TextEditInput::updateScroll() {
12251244
int pageRows = _height / _charHeight;
12261245
if (_cursorRow + 1 < pageRows) {
12271246
_scroll = 0;
1228-
} else if (_cursorRow > _scroll + pageRows || _cursorRow <= _scroll) {
1247+
} else if (_cursorRow >= _scroll + pageRows || _cursorRow <= _scroll) {
12291248
// cursor outside current view
12301249
_scroll = _cursorRow - (pageRows / 2);
12311250
}

src/ui/textedit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct EditTheme {
4444
int _syntax_text;
4545
int _syntax_command;
4646
int _syntax_statement;
47+
int _syntax_digit;
4748
};
4849

4950
struct EditBuffer {
@@ -107,6 +108,7 @@ struct TextEditInput : public FormEditInput {
107108
kText,
108109
kCommand,
109110
kStatement,
111+
kDigit,
110112
};
111113

112114
void drawText(int x, int y, const char *str, int length, SyntaxState &state);

0 commit comments

Comments
 (0)