: nply/wmenu

commit f627466663050e59e7372751497d4a520fd0c164
parent b8e79aeac945364a70f17f3f8e6faffd25da238e
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Tue, 13 Oct 2026 23:18:08 +0530

Avoid unintended first row when finishing multi-select
3 files changed, 15 insertions(+), 2 deletions(-)
M
README
|
2
+-
M
test_stream.c
|
8
++++++++
M
wmenu.c
|
7
++++++-
diff --git a/README b/README
@@ -28,7 +28,7 @@ Useful flags:
 -x px -y px -w px   position and width
 -c                  center window
 -l lines            visible list lines; -l-1 fills the screen (default 5)
--m                  select multiple entries; Ctrl+Enter adds one
+-m                  select multiple entries; Ctrl+Enter adds one, Enter finishes
 -i                  ignore ASCII case while matching
 -V                  enable vi support; Ctrl+Alt+V toggles vi mode
 -d                  use normal Windows edit shortcuts instead of emacs-ish keys
diff --git a/test_stream.c b/test_stream.c
@@ -254,6 +254,14 @@ int main(int argc, char **argv)
     SetWindowTextW(input_hwnd, L"\x00e9"); /* UTF-8 edit text goes through the search path. */
     while (search_pos < loaded_count()) search_step();
     assert(match_count == 1 && matches[0] == 60003);
+    add_selection();
+    assert(selected_count == 1 && !strcmp(selected[0], "caf\xc3\xa9"));
+    assert(SendMessageW(list_hwnd, LB_GETCURSEL, 0, 0) == LB_ERR);
+    char *after_add = current_text();
+    assert(after_add && !*after_add); /* Enter would output only added rows. */
+    free(after_add);
+    list_move(1);
+    assert(SendMessageW(list_hwnd, LB_GETCURSEL, 0, 0) == 0);
     DeleteFiber(search_fiber);
     ConvertFiberToThread();
     DestroyWindow(main_hwnd);
diff --git a/wmenu.c b/wmenu.c
@@ -477,7 +477,12 @@ static void add_selection(void)
     selected = grown;
     selected[selected_count++] = s;
     SetWindowTextW(input_hwnd, L"");
-    if (has_items) refill_list("");
+    if (has_items) {
+        refill_list("");
+        SendMessageW(list_hwnd, LB_SETCURSEL, -1, 0);
+        last_row = -1;
+        UpdateWindow(list_hwnd);
+    }
 }
 
 static void finish(void)