aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/main.c b/main.c
index 4a831ca..29eb060 100644
--- a/main.c
+++ b/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);
- }
+ size_t len = strlen(menu->input);
+ 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);
}
}