diff --git a/lib/common.sh b/lib/common.sh index 740067b..f75ed9c 100755 --- a/lib/common.sh +++ b/lib/common.sh @@ -175,8 +175,17 @@ show_cursor() { # Keyboard input handling (simple and robust) read_key() { - local key rest - IFS= read -r -s -n 1 key || return 1 + local key rest read_status + + # Read with explicit status check + IFS= read -r -s -n 1 key + read_status=$? + + # Handle read failure (Ctrl+D, EOF, etc.) - treat as quit + if [[ $read_status -ne 0 ]]; then + echo "QUIT" + return 0 + fi # Raw typing mode (filter): map most keys to CHAR: if [[ "${MOLE_READ_KEY_FORCE_CHAR:-}" == "1" ]]; then diff --git a/lib/paginated_menu.sh b/lib/paginated_menu.sh index 95630c9..011d133 100755 --- a/lib/paginated_menu.sh +++ b/lib/paginated_menu.sh @@ -637,7 +637,26 @@ paginated_multi_select() { draw_menu continue fi - # In normal mode: confirm and exit with current selections + # In normal mode: smart Enter behavior + # 1. Check if any items are already selected + local has_selection=false + for ((i = 0; i < total_items; i++)); do + if [[ ${selected[i]} == true ]]; then + has_selection=true + break + fi + done + + # 2. If nothing selected, auto-select current item + if [[ $has_selection == false ]]; then + local idx=$((top_index + cursor_pos)) + if [[ $idx -lt ${#view_indices[@]} ]]; then + local real="${view_indices[idx]}" + selected[real]=true + fi + fi + + # 3. Confirm and exit with current selections local -a selected_indices=() for ((i = 0; i < total_items; i++)); do if [[ ${selected[i]} == true ]]; then