feat: switch text to UTF-8; add Unicode key events, dead keys & Czech layout; fix numpad navigation; add NumLock support
This commit is contained in:
1 parent
32660ddd1a
commit
2aa6360b3d
101 files changed
+3733
-1639
No files matched your search
@@ -415,25 +415,13 @@ extern "C" void _start() {
|
||||
} else if (key.scancode == 0x01) {
|
||||
g_pathbar_open = false;
|
||||
} else if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (g_pathbar_cursor > 0) {
|
||||
for (int i = g_pathbar_cursor - 1; i < g_pathbar_len - 1; i++)
|
||||
g_pathbar_text[i] = g_pathbar_text[i + 1];
|
||||
g_pathbar_len--;
|
||||
g_pathbar_cursor--;
|
||||
g_pathbar_text[g_pathbar_len] = '\0';
|
||||
}
|
||||
} else if (key.scancode == 0x4B) {
|
||||
if (g_pathbar_cursor > 0) g_pathbar_cursor--;
|
||||
} else if (key.scancode == 0x4D) {
|
||||
if (g_pathbar_cursor < g_pathbar_len) g_pathbar_cursor++;
|
||||
} else if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127 && g_pathbar_len < 254) {
|
||||
for (int i = g_pathbar_len; i > g_pathbar_cursor; i--)
|
||||
g_pathbar_text[i] = g_pathbar_text[i - 1];
|
||||
g_pathbar_text[g_pathbar_cursor] = key.ascii;
|
||||
g_pathbar_cursor++;
|
||||
g_pathbar_len++;
|
||||
g_pathbar_text[g_pathbar_len] = '\0';
|
||||
montauk::utf8::erase_before(g_pathbar_text, &g_pathbar_len, &g_pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4B) {
|
||||
g_pathbar_cursor = montauk::utf8::prev_boundary(g_pathbar_text, g_pathbar_cursor);
|
||||
} else if (montauk::nav_scancode(key) == 0x4D) {
|
||||
g_pathbar_cursor = montauk::utf8::next_boundary(g_pathbar_text, g_pathbar_len, g_pathbar_cursor);
|
||||
} else {
|
||||
montauk::utf8::insert_key(g_pathbar_text, &g_pathbar_len, 255, &g_pathbar_cursor, key);
|
||||
}
|
||||
redraw = true;
|
||||
goto done_keys;
|
||||
@@ -441,12 +429,12 @@ extern "C" void _start() {
|
||||
|
||||
// Autocomplete interaction (when editing with autocomplete open)
|
||||
if (g_ac_open && g_editing) {
|
||||
if (key.scancode == 0x48) { // Up
|
||||
if (montauk::nav_scancode(key) == 0x48) { // Up
|
||||
g_ac_sel = (g_ac_sel - 1 + g_ac_count) % g_ac_count;
|
||||
redraw = true;
|
||||
goto done_keys;
|
||||
}
|
||||
if (key.scancode == 0x50) { // Down
|
||||
if (montauk::nav_scancode(key) == 0x50) { // Down
|
||||
g_ac_sel = (g_ac_sel + 1) % g_ac_count;
|
||||
redraw = true;
|
||||
goto done_keys;
|
||||
@@ -498,7 +486,7 @@ extern "C" void _start() {
|
||||
redraw = true;
|
||||
}
|
||||
// Arrow keys (with Shift = extend selection)
|
||||
else if (key.scancode == 0x48 && !g_editing) { // Up
|
||||
else if (montauk::nav_scancode(key) == 0x48 && !g_editing) { // Up
|
||||
if (key.shift) {
|
||||
if (!g_has_selection) { g_anchor_col = g_sel_col; g_anchor_row = g_sel_row; g_has_selection = true; }
|
||||
if (g_sel_row > 0) g_sel_row--;
|
||||
@@ -509,7 +497,7 @@ extern "C" void _start() {
|
||||
ensure_sel_visible();
|
||||
redraw = true;
|
||||
}
|
||||
else if (key.scancode == 0x50 && !g_editing) { // Down
|
||||
else if (montauk::nav_scancode(key) == 0x50 && !g_editing) { // Down
|
||||
if (key.shift) {
|
||||
if (!g_has_selection) { g_anchor_col = g_sel_col; g_anchor_row = g_sel_row; g_has_selection = true; }
|
||||
if (g_sel_row < MAX_ROWS - 1) g_sel_row++;
|
||||
@@ -520,7 +508,7 @@ extern "C" void _start() {
|
||||
ensure_sel_visible();
|
||||
redraw = true;
|
||||
}
|
||||
else if (key.scancode == 0x4B && !g_editing) { // Left
|
||||
else if (montauk::nav_scancode(key) == 0x4B && !g_editing) { // Left
|
||||
if (key.shift) {
|
||||
if (!g_has_selection) { g_anchor_col = g_sel_col; g_anchor_row = g_sel_row; g_has_selection = true; }
|
||||
if (g_sel_col > 0) g_sel_col--;
|
||||
@@ -531,7 +519,7 @@ extern "C" void _start() {
|
||||
ensure_sel_visible();
|
||||
redraw = true;
|
||||
}
|
||||
else if (key.scancode == 0x4D && !g_editing) { // Right
|
||||
else if (montauk::nav_scancode(key) == 0x4D && !g_editing) { // Right
|
||||
if (key.shift) {
|
||||
if (!g_has_selection) { g_anchor_col = g_sel_col; g_anchor_row = g_sel_row; g_has_selection = true; }
|
||||
if (g_sel_col < MAX_COLS - 1) g_sel_col++;
|
||||
@@ -545,14 +533,8 @@ extern "C" void _start() {
|
||||
// Backspace
|
||||
else if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (g_editing) {
|
||||
if (g_edit_cursor > 0) {
|
||||
for (int i = g_edit_cursor - 1; i < g_edit_len - 1; i++)
|
||||
g_edit_buf[i] = g_edit_buf[i + 1];
|
||||
g_edit_len--;
|
||||
g_edit_cursor--;
|
||||
g_edit_buf[g_edit_len] = '\0';
|
||||
if (montauk::utf8::erase_before(g_edit_buf, &g_edit_len, &g_edit_cursor))
|
||||
update_autocomplete();
|
||||
}
|
||||
redraw = true;
|
||||
} else {
|
||||
undo_push();
|
||||
@@ -567,15 +549,10 @@ extern "C" void _start() {
|
||||
}
|
||||
}
|
||||
// Delete key
|
||||
else if (key.scancode == 0x53) {
|
||||
else if (montauk::nav_scancode(key) == 0x53) {
|
||||
if (g_editing) {
|
||||
if (g_edit_cursor < g_edit_len) {
|
||||
for (int i = g_edit_cursor; i < g_edit_len - 1; i++)
|
||||
g_edit_buf[i] = g_edit_buf[i + 1];
|
||||
g_edit_len--;
|
||||
g_edit_buf[g_edit_len] = '\0';
|
||||
if (montauk::utf8::erase_at(g_edit_buf, &g_edit_len, g_edit_cursor))
|
||||
update_autocomplete();
|
||||
}
|
||||
redraw = true;
|
||||
} else {
|
||||
undo_push();
|
||||
@@ -590,18 +567,18 @@ extern "C" void _start() {
|
||||
}
|
||||
}
|
||||
// Edit mode arrow keys (cursor movement within formula bar)
|
||||
else if (key.scancode == 0x4B && g_editing) {
|
||||
if (g_edit_cursor > 0) g_edit_cursor--;
|
||||
else if (montauk::nav_scancode(key) == 0x4B && g_editing) {
|
||||
g_edit_cursor = montauk::utf8::prev_boundary(g_edit_buf, g_edit_cursor);
|
||||
update_autocomplete();
|
||||
redraw = true;
|
||||
}
|
||||
else if (key.scancode == 0x4D && g_editing) {
|
||||
if (g_edit_cursor < g_edit_len) g_edit_cursor++;
|
||||
else if (montauk::nav_scancode(key) == 0x4D && g_editing) {
|
||||
g_edit_cursor = montauk::utf8::next_boundary(g_edit_buf, g_edit_len, g_edit_cursor);
|
||||
update_autocomplete();
|
||||
redraw = true;
|
||||
}
|
||||
// Home key
|
||||
else if (key.scancode == 0x47) {
|
||||
else if (montauk::nav_scancode(key) == 0x47) {
|
||||
if (g_editing) {
|
||||
g_edit_cursor = 0;
|
||||
update_autocomplete();
|
||||
@@ -613,7 +590,7 @@ extern "C" void _start() {
|
||||
redraw = true;
|
||||
}
|
||||
// End key
|
||||
else if (key.scancode == 0x4F) {
|
||||
else if (montauk::nav_scancode(key) == 0x4F) {
|
||||
if (g_editing) {
|
||||
g_edit_cursor = g_edit_len;
|
||||
update_autocomplete();
|
||||
@@ -670,23 +647,16 @@ extern "C" void _start() {
|
||||
redraw = true;
|
||||
}
|
||||
// Printable character: start editing or insert
|
||||
else if ((unsigned char)key.ascii >= 32
|
||||
&& (unsigned char)key.ascii != 127 && !key.ctrl) {
|
||||
else if (montauk::utf8::key_codepoint(key) && !key.ctrl) {
|
||||
if (!g_editing) {
|
||||
clear_selection();
|
||||
g_editing = true;
|
||||
g_edit_buf[0] = key.ascii;
|
||||
g_edit_buf[1] = '\0';
|
||||
g_edit_len = 1;
|
||||
g_edit_cursor = 1;
|
||||
} else if (g_edit_len < CELL_TEXT_MAX - 1) {
|
||||
for (int i = g_edit_len; i > g_edit_cursor; i--)
|
||||
g_edit_buf[i] = g_edit_buf[i - 1];
|
||||
g_edit_buf[g_edit_cursor] = key.ascii;
|
||||
g_edit_len++;
|
||||
g_edit_cursor++;
|
||||
g_edit_buf[g_edit_len] = '\0';
|
||||
g_edit_buf[0] = '\0';
|
||||
g_edit_len = 0;
|
||||
g_edit_cursor = 0;
|
||||
}
|
||||
montauk::utf8::insert_key(g_edit_buf, &g_edit_len, CELL_TEXT_MAX,
|
||||
&g_edit_cursor, key);
|
||||
update_autocomplete();
|
||||
redraw = true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user