Simplify movewordedge

This commit is contained in:
adnano 2024-02-27 08:07:16 -05:00
parent c37c3fe38e
commit 8bcad262a4

20
main.c
View file

@ -291,24 +291,14 @@ static size_t nextrune(struct menu *menu, int incr) {
return n;
}
// Move the cursor to the beginning or end of the word, skipping over any preceding whitespace.
static void movewordedge(struct menu *menu, int dir) {
if (dir < 0) {
// Move to beginning of word
while (menu->cursor > 0 && menu->input[nextrune(menu, -1)] == ' ') {
menu->cursor = nextrune(menu, -1);
}
while (menu->cursor > 0 && menu->input[nextrune(menu, -1)] != ' ') {
menu->cursor = nextrune(menu, -1);
}
} else {
// Move to end of word
size_t len = strlen(menu->input);
while (menu->cursor < len && menu->input[menu->cursor] == ' ') {
menu->cursor = nextrune(menu, +1);
}
while (menu->cursor < len && menu->input[menu->cursor] != ' ') {
menu->cursor = nextrune(menu, +1);
while (menu->cursor > 0 && menu->cursor < len && menu->input[nextrune(menu, dir)] == ' ') {
menu->cursor = nextrune(menu, dir);
}
while (menu->cursor > 0 && menu->cursor < len && menu->input[nextrune(menu, dir)] != ' ') {
menu->cursor = nextrune(menu, dir);
}
}