Skip to content

fix(shell): let Alt+Backspace delete a word inside modal text input#1788

Open
kevinWangSheng wants to merge 2 commits intoMoonshotAI:mainfrom
kevinWangSheng:fix/modal-alt-backspace
Open

fix(shell): let Alt+Backspace delete a word inside modal text input#1788
kevinWangSheng wants to merge 2 commits intoMoonshotAI:mainfrom
kevinWangSheng:fix/modal-alt-backspace

Conversation

@kevinWangSheng
Copy link
Copy Markdown

@kevinWangSheng kevinWangSheng commented Apr 8, 2026

Closes #1744.

Symptom

In the /btw panel (and any other modal text input delegate), pressing Alt+Backspace did nothing. Outside the modal it worked as expected and deleted the previous word.

Cause

The shell's running-prompt key bindings register a global escape handler with eager=True. With eager=True, prompt_toolkit fires that handler as soon as it sees the leading escape byte, before it has a chance to wait for a possible follow-up key. The default emacs bindings include ("escape", "backspace") -> backward-kill-word, so the eager escape handler was swallowing the prefix and the two-key sequence never matched.

The eager escape only needs to be eager when no modal text input is active (so a stray Esc dismisses the modal layer or cancels). When a modal text input delegate is active we want normal sequence resolution.

Fix

Make the eager flag on the escape binding a Condition instead of a constant True: it stays eager unless the active UI state is MODAL_TEXT_INPUT. Inside a text-accepting modal, prompt_toolkit waits for the next key and resolves escape,backspace to backward-kill-word normally.

Tests

  • tests/ui_and_conv/test_modal_lifecycle.py: three new cases covering _active_ui_state() for text-input, hidden-input and non-text-input delegates.
  • Full suite: 2200 passed.

Verification

  • prek run --all-files
  • make check-shell
  • make test-shell

Before: in /btw, Alt+Backspace was a no-op.
After: in /btw, Alt+Backspace deletes the previous word.


Open with Devin

The modal escape key binding in CustomPromptSession used eager=True
unconditionally. prompt_toolkit treats an eager match on a shorter key
sequence as a hard cut-off: longer sequences like `escape backspace`
(Alt+Backspace → backward-kill-word) are never even considered. That
meant typing in the "Other" field of an ExitPlanMode or AskUserQuestion
panel and pressing Alt+Backspace closed the panel instead of deleting
the last word — same story for Alt+Delete, Alt+f, Alt+b and friends.

Drop eager while the active modal reports MODAL_TEXT_INPUT. The escape
binding still fires on a plain Escape (after the short prompt_toolkit
escape timeout) so Escape-to-cancel still works in text-input mode.
Outside text-input modes eager stays on, so closing a multi-choice
panel remains instant.

Also add unit tests pinning the three _active_ui_state() branches that
feed the eager filter.

Closes MoonshotAI#1744
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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.

Bug Report: Alt+Backspace incorrectly closes question panels instead of deleting word

1 participant