Skip to content

Fix checkbox returning empty string on Alt-Enter#515

Open
uttam12331 wants to merge 1 commit into
tmbo:masterfrom
uttam12331:fix/324-checkbox-alt-enter
Open

Fix checkbox returning empty string on Alt-Enter#515
uttam12331 wants to merge 1 commit into
tmbo:masterfrom
uttam12331:fix/324-checkbox-alt-enter

Conversation

@uttam12331

Copy link
Copy Markdown

Summary

Closes #324.

In a checkbox prompt, submitting with Alt-Enter (Meta+Enter) returns the empty string "" instead of the list of selected values. Only plain Enter (Keys.ControlM) was bound to the submission handler, so the escape, c-m sequence fell through to the default and returned "".

Reproduction (before the fix):

# space to select first choice, then Alt-Enter to submit
KeyInputs.SPACE + KeyInputs.ESCAPE + KeyInputs.ENTER  ->  ''   # expected ['foo']

Fix

Bind the Alt-Enter sequence (Keys.Escape, Keys.ControlM) to the same set_answer handler as plain Enter, so it submits and returns the selected values:

@bindings.add(Keys.ControlM, eager=True)
@bindings.add(Keys.Escape, Keys.ControlM, eager=True)
def set_answer(event):
    ...

Tests

Added test_select_first_choice_with_alt_enter asserting Alt-Enter returns ['foo'] (matching the plain-Enter behavior).

Verified locally: pytest tests/prompts/test_checkbox.py34 passed; ruff check clean.

In a checkbox prompt, submitting with Alt-Enter (Meta+Enter) returned the
empty string instead of the list of selected values, because only plain
Enter (Keys.ControlM) was bound to the submission handler; the
'escape, c-m' sequence fell through to the default and returned ''.

Bind the Alt-Enter sequence (Keys.Escape, Keys.ControlM) to the same
set_answer handler so it submits and returns the selected values like Enter.

Closes tmbo#324
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validating a checkbox with Alt-Enter makes it return the empty string

1 participant