Simplify movewordedge - wmenu - 🔧 fork of wmenu
(HTM) git clone git@git.drkhsh.at/wmenu.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 8bcad262a4d047140767d9467ac5526bb768a95e
(DIR) parent c37c3fe38e77398fba65d169c664f569fbab9760
(HTM) Author: adnano <me@adnano.co>
Date: Tue, 27 Feb 2024 08:07:16 -0500
Simplify movewordedge
Diffstat:
M main.c | 24 +++++++-----------------
1 file changed, 7 insertions(+), 17 deletions(-)
---
(DIR) diff --git 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);
}
}