Repository navigation
story: Add an application-owned completion menu to the Input story - #3607
Conversation
Composes the completion interaction that longbridge#3560 asks applications to own, following the direction from the longbridge#3490 review: InputState carries no completion state. The example owns the candidate data, filtering and ranking (static variable table), trigger detection and dismissal (an InputEvent::Change rescan of the $-token under the caret), keyboard ownership (capture_action intercepts MoveUp/MoveDown/Escape/IndentInline while the menu is open), the Enter decision (accept vs. submit), and the accepted edit (set_selected_range + replace swaps the typed $prefix in one atomic undo step, revalidated against the current buffer). The menu anchors to the input region as a deferred overlay; caret anchoring via cursor_layout()/range_to_bounds() is noted for applications that need it. Run with: cargo run -p completion
|
We looked into the red "Checks" job: it's pre-existing on Happy to send a small fix for the release-notes baseline if useful — otherwise leaving it to you as a main-side matter. |
|
The menu is refreshed only on For the unrelated Checks failure, a separate narrow typos fix would be useful; please preserve the correct author handles and avoid disabling checks for the whole release-notes file. Reviewed by ChatGPT on behalf of @huacnlee. |
Caret movement notifies without emitting any event, so a menu opened on a $-token survived Home / arrow-key / click moves that left the token: it kept capturing navigation and Tab, and the first Enter dismissed it instead of submitting. Found by review; no native reproduction needed. The trigger rescan is now ground truth at every moment of authority: - render re-runs the rescan against the live caret every frame, so a menu whose token the caret left is gone that same frame (no notify on this path — the frame under construction already reflects it); - every captured key (MoveUp / MoveDown / Escape / IndentInline) and PressEnter revalidate the trigger before acting, so keyboard ownership never outlives the token it was granted for — a stale menu dismisses and the key falls through to the input (Enter submits). Regression tests cover leaving the token without changing its text (Home, whitespace boundaries, mid-token $ that must never trigger) plus trigger placement and ranking.
|
Thank you for the careful review — the static finding was correct, and it's fixed in fe2d1ec. The bug: you're right that caret movement only notifies and never emits an event, so a menu opened on a The fix makes the trigger rescan ground truth at every moment of authority, since no selection event exists to observe:
Regression tests cover exactly the requested case — leaving the token without changing its text ( The typos baseline: separate as requested — #3608 ignores the two exact handle strings via Happy to take another pass on anything. |
Fixes the red **Checks** job on `main` (first noticed from #3607): the v0.8.0 release notes credit `@UncertaintyDeterminesYou4ndMe` and `@alex-vas`, and the typos tokenizer reads those handles as the misspelled words `nd` and `vas` — 15 findings, all in `release-notes.md`, reproduced with the pinned `typos-cli 1.40.0` on a pristine checkout. The fix is the narrowest one that meets the constraints from the #3607 review: the **exact handle strings** are added to `extend-ignore-re`, so - the handles stay verbatim (nothing in `release-notes.md` is touched), - `release-notes.md` itself is still checked — only the two handle matches are skipped, - no word-level or file-level disable that could mask a real typo elsewhere. Verified locally with the pinned `typos-cli 1.40.0`: `typos` exits 0 on the full repo with this change, and both recent `Checks` runs on `main` fail exactly on these findings.
|
Sorry, do not add more example, just add to story. |
The maintainer asked for no new example crate, so the composition moves from examples/completion into a "Completion" section of the Input story. The popup now uses popover_style and ListItem rows, the surface and rows Combobox uses, instead of approximating them. The four captured-key handlers share one revalidation check. The leaving-the-token regression now drives the mounted story with keystrokes (type `echo $HO`, then `home enter` with no edit), and fails if the revalidation is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Done: the standalone example is gone and the completion menu is now a "Completion" section of the Input story ( While moving it, the popup now uses |
Follows up on #3560 and the direction from the #3490 review: instead of adding completion state to
InputState, the Input story gains a Completion section, an application-owned completion menu around a single-lineInputbuilt only on existing public APIs. No changes to gpui-base or gpui-component.What it shows
Type
$and a menu of shell-style variables opens. Typing filters it, the keyboard drives it, and accepting replaces the typed$prefixwith$NAME. The application owns each part:InputEvent::Changerescans the$-token under the caret ($must start the text or follow whitespace, soa$bnever triggers). Caret movement emits no event, sorenderrepeats the rescan against the live caret.capture_actionon the input's wrapper takesMoveUp/MoveDown/Escape/IndentInline(tab) while the menu is open. Each key first checks that the menu still belongs to the token under the caret; a stale menu dismisses and the key goes to the input.InputEvent::PressEnteraccepts with a current menu and submits otherwise.set_selected_range+replaceswap it in one undo step.The menu uses
popover_styleandListItemrows, the same surface and rows Combobox uses, and anchors to the input region. Applications that need caret anchoring can usecursor_layout()/range_to_bounds().Files
crates/story/src/stories/input_completion.rs: the composition and its tests.crates/story/src/stories/input_story.rs,mod.rs: mount it as the "Completion" section.Testing
cargo clippy -p gpui-component-story --tests -- --deny warnings,cargo fmt --check,typos: clean.cargo test -p gpui-component-story input_completion: 4 tests pass. Two drive the story with keystrokes: select and accept withdown/tab/enter, and the review's regression (typeecho $HO, presshome enterwith no edit in between; Enter submits and the text is unchanged). Removing the revalidation makes the regression test fail.Refs #3560.
🤖 Generated with Claude Code