1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 19:44:44 +00:00

Enter to select the next step

This commit is contained in:
Tw93
2025-10-14 19:18:03 +08:00
parent 5ec2ca0c46
commit 05e3ec78dc
2 changed files with 31 additions and 3 deletions

View File

@@ -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:<key>
if [[ "${MOLE_READ_KEY_FORCE_CHAR:-}" == "1" ]]; then

View File

@@ -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