From bbfbf8f36c1e7dd1912d0646a3ae271a8c69e6b9 Mon Sep 17 00:00:00 2001 From: adnano Date: Tue, 27 Feb 2024 12:00:10 -0500 Subject: Revert "Simplify movewordedge" This reverts commit 8bcad262a4d047140767d9467ac5526bb768a95e. --- menu.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/menu.c b/menu.c index c646666..7f4f461 100644 --- a/menu.c +++ b/menu.c @@ -337,12 +337,23 @@ static size_t nextrune(struct menu *menu, int incr) { // Move the cursor to the beginning or end of the word, skipping over any preceding whitespace. static void movewordedge(struct menu *menu, int dir) { - 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); + 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); + } } } -- cgit v1.2.3