Simplify movewordedge
This commit is contained in:
parent
c37c3fe38e
commit
8bcad262a4
1 changed files with 7 additions and 17 deletions
20
main.c
20
main.c
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue