Skip to content

Commit 1d2e2ea

Browse files
committed
UI: fix underscore input
1 parent a5c49a5 commit 1d2e2ea

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/platform/sdl/keymap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const int shiftmap[][2] = {
6363
{'8', '*'},
6464
{'9', '('},
6565
{'0', ')'},
66-
{'-', '-'},
66+
{'-', '_'},
6767
{'=', '+'},
6868
{'[', '{'},
6969
{']', '}'},

src/ui/textedit.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const char *helpText =
8282
"F1,A-h keyword help\n"
8383
"F9, C-r run\n";
8484

85-
static inline bool match(const char *str, const char *pattern , int len) {
85+
inline bool match(const char *str, const char *pattern , int len) {
8686
int i, j;
8787
for (i = 0, j = 0; i < len; i++, j += 2) {
8888
if (str[i] != pattern[j] && str[i] != pattern[j + 1]) {
@@ -92,6 +92,10 @@ static inline bool match(const char *str, const char *pattern , int len) {
9292
return i == len;
9393
}
9494

95+
inline bool is_comment(const char *str, int offs) {
96+
return str[offs] == '\'' || str[offs] == '#' || match(str + offs, "RrEeMm ", 3);
97+
}
98+
9599
//
96100
// EditTheme
97101
//
@@ -426,7 +430,7 @@ void TextEditInput::drawText(int x, int y, const char *str,
426430

427431
// find the end of the current segment
428432
while (i < length) {
429-
if (str[i] == '\'' || match(str + i, "RrEeMm ", 3)) {
433+
if (is_comment(str, i)) {
430434
next = length - i;
431435
nextState = kComment;
432436
break;
@@ -962,7 +966,11 @@ uint32_t TextEditInput::getHash(const char *str, int offs, int &count) {
962966
uint32_t result = 0;
963967
if ((offs == 0 || str[offs - 1] == ' ' || str[offs - 1] == '\n')
964968
&& str[offs] != ' ' && str[offs] != '\n' && str[offs] != '\0') {
965-
for (count = 0; count < keyword_max_len && isalpha(str[offs + count]); count++) {
969+
for (count = 0; count < keyword_max_len; count++) {
970+
char ch = str[offs + count];
971+
if (!isalpha(ch) && ch != '_') {
972+
break;
973+
}
966974
result += tolower(str[offs + count]);
967975
result += (result << 3);
968976
result ^= (result >> 1);
@@ -998,7 +1006,7 @@ int TextEditInput::getIndent(char *spaces, int len, int pos) {
9981006
int j = i + 4;
9991007
while (buf[j] != 0 && buf[j] != '\n') {
10001008
// line also 'ends' at start of comments
1001-
if (strncasecmp(buf + j, "rem", 3) == 0 || buf[j] == '\'') {
1009+
if (is_comment(buf, j)) {
10021010
break;
10031011
}
10041012
j++;

0 commit comments

Comments
 (0)