mirror of
https://codeberg.org/adnano/wmenu.git
synced 2025-10-29 05:40:20 -04:00
Simplify movewordedge
This commit is contained in:
parent
c37c3fe38e
commit
8bcad262a4
1 changed files with 7 additions and 17 deletions
24
main.c
24
main.c
|
|
@ -291,24 +291,14 @@ static size_t nextrune(struct menu *menu, int incr) {
|
||||||
return n;
|
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) {
|
static void movewordedge(struct menu *menu, int dir) {
|
||||||
if (dir < 0) {
|
size_t len = strlen(menu->input);
|
||||||
// Move to beginning of word
|
while (menu->cursor > 0 && menu->cursor < len && menu->input[nextrune(menu, dir)] == ' ') {
|
||||||
while (menu->cursor > 0 && menu->input[nextrune(menu, -1)] == ' ') {
|
menu->cursor = nextrune(menu, dir);
|
||||||
menu->cursor = nextrune(menu, -1);
|
}
|
||||||
}
|
while (menu->cursor > 0 && menu->cursor < len && menu->input[nextrune(menu, dir)] != ' ') {
|
||||||
while (menu->cursor > 0 && menu->input[nextrune(menu, -1)] != ' ') {
|
menu->cursor = nextrune(menu, dir);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue