From 8bcad262a4d047140767d9467ac5526bb768a95e Mon Sep 17 00:00:00 2001 From: adnano Date: Tue, 27 Feb 2024 08:07:16 -0500 Subject: Simplify movewordedge --- main.c | 24 +++++++----------------- 1 file 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); } } -- cgit v1.2.3