Repository navigation
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
This branch has not been deployed
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.
Issue for this PR
Closes #50962
Type of change
What does this PR do?
A file-defined slash command needs two
Enterpresses to run, while a built-in command runs on the first one. Typing/goodand pressingEnteronly shifts the cursor by one space; a secondEnteris what actually submits.Why.
Enteris bound twice.packages/tui/src/config/keybind.tsgivesreturnto bothprompt.autocomplete.select(:217) andinput_submit(:163), and the autocomplete registers its bindings withenabled: () => Boolean(store.visible)(packages/tui/src/component/prompt/autocomplete.tsx:583). While the slash list is open,Entertherefore always means "select", and submit never sees the key.What the selection then does is what makes the two paths differ. A built-in command comes from
useCommandSlashes()and itsonSelectiskeymap.dispatchCommand(name), so it executes immediately (packages/tui/src/keymap.tsx:286). A file-defined command comes fromsync.data.command, and itsonSelectonly rewrites the input to"/" + name + " "and moves the cursor (autocomplete.tsx:456-462). So for a file-defined command the firstEnterselects, and the command waits for a secondEnter.The fix. Collapse the list once the typed text already names a whole command, so the next
Enterreaches the input's own submit path (prompt/index.tsx:1391-1395<textarea onSubmit>->submit()->submitInner()), which dispatches the command throughsdk.client.session.command. No new prop, no keymap change.isCompleteCommandcompares the typed text against the trimmeddisplayof the offered commands. The trimming matters: the list pads everydisplayto the width of the longest entry before rendering (autocomplete.tsx:468-473). Aliases count too, matching what the fuzzer searches.Note this uses
setStore("visible", false)rather than the existinghide():hide()is for a half-typed trigger and deletes the input text when it does not end in a space, which would have discarded the command the user just finished typing.Typing another character reopens the list, because the reopen branch below only requires the text before the cursor to start with
/and contain no whitespace (autocomplete.tsx:716), so/good->/good-still lists/good-thing.Known limits, so the reviewer can weigh them:
/goodto/good-thingwith the arrow keys takes one more keystroke to bring the list back. Confirm-and-prefix-browsing are in tension here; I preferred the reported case (type the name, pressEnter)./nameand waits for a followingEnter, exactly as before. Collapsing the list cannot change that path, because the selection itself is what inserts the text. If you would rather have a selected file-defined command submit immediately (like a built-in, which executes on selection), that is a different change and I can do it on top.Enterpresses it takes to get there, not what runs.How did you verify your code works?
cd packages/tui && bun test test/component/autocomplete.test.ts— 5 pass, 0 fail. The newisCompleteCommandtests pin the behaviour that decides this fix: a name that differs fromdisplayonly by list padding matches, an alias matches, and a prefix (/goo), a name with arguments (/good clean up), unrelated text and an empty list do not, so the list stays open while the name is still being typed.cd packages/tui && bun test— 199 pass, 1 skip, 0 fail across 46 files, so nothing else in the package changed behaviour.cd packages/tui && bun run typecheck,bun run lint(oxlint) andbunx prettier --checkare clean on both files. The two oxlintconsistent-returnwarnings on this file also reproduce on the unmodified file, so they are pre-existing.Enterbinding is gated onstore.visible, so once the list is collapsed that binding is inactive and the key falls through to the textarea'sonSubmit, which is the path a successful submit already takes.I did not add an end-to-end render test that presses
Enterand asserts the command dispatched: mountingPromptneeds the full SDK/session/editor provider stack, and I did not want to introduce that harness inside this fix. The predicate is unit-tested and the fall-through is by construction; say the word if you want the integration test as well.Screenshots / recordings
Not applicable, this is TUI key handling rather than a visual change.
Checklist