fix(shell): let Alt+Backspace delete a word inside modal text input#1788
Open
kevinWangSheng wants to merge 2 commits intoMoonshotAI:mainfrom
Open
fix(shell): let Alt+Backspace delete a word inside modal text input#1788kevinWangSheng wants to merge 2 commits intoMoonshotAI:mainfrom
kevinWangSheng wants to merge 2 commits intoMoonshotAI:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1744.
Symptom
In the
/btwpanel (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
escapehandler witheager=True. Witheager=True, prompt_toolkit fires that handler as soon as it sees the leadingescapebyte, 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
eagerflag on the escape binding aConditioninstead of a constantTrue: it stays eager unless the active UI state isMODAL_TEXT_INPUT. Inside a text-accepting modal, prompt_toolkit waits for the next key and resolvesescape,backspacetobackward-kill-wordnormally.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.Verification
prek run --all-filesmake check-shellmake test-shellBefore: in
/btw, Alt+Backspace was a no-op.After: in
/btw, Alt+Backspace deletes the previous word.