aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradnano <me@adnano.co>2024-02-27 08:07:16 -0500
committeradnano <me@adnano.co>2024-02-27 08:07:16 -0500
commit8bcad262a4d047140767d9467ac5526bb768a95e (patch)
treef0d588fb44177c0f0543af1d18631871591e2990
parentc37c3fe38e77398fba65d169c664f569fbab9760 (diff)
downloadwmenu-8bcad262a4d047140767d9467ac5526bb768a95e.tar.gz
Simplify movewordedge
-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);
}
}