Repository navigation
Reusable prompt snippets insertable in the composer (#189) - #1575
Conversation
Snippets (name + text) live in settings.promptSnippets, edited under Settings > Agents. Typing @name in the composer lists matching snippets above file matches; accepting replaces the token with the snippet text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e03590032
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /** Snippets first, then files; one index walks both. */ | ||
| const mentionCount = snippetMatches.length + mentionFiles.length; | ||
| // Files land 150ms after the query changes; clamp so a shorter snippet | ||
| // list never leaves the highlight past the end in between. | ||
| const mentionActive = Math.max(0, Math.min(mentionIndex, mentionCount - 1)); |
There was a problem hiding this comment.
Keep keyboard selection stable while files load
When snippets match, the popup opens immediately, but the pending file lookup in refreshMention still calls setMentionIndex(0) when it resolves. If the user presses ArrowDown during the 150 ms debounce or while file lookup is pending, the highlight silently jumps back to the first snippet, so Enter can insert a different prompt than the one the user selected. Preserve the current unified index when files arrive, or reset it only when the query itself changes.
Useful? React with 👍 / 👎.
| onPersist={async (promptSnippets) => { | ||
| setError(null); | ||
| try { | ||
| await onSaveSettings({ promptSnippets }); |
There was a problem hiding this comment.
Serialize prompt-snippet saves
This callback bypasses SettingsModal's savingRef/setSaving guard, leaving every snippet control enabled while settings.set is pending. In a remote/web session, deleting two snippets before the first round trip completes sends two full arrays derived from the same stale snippets prop—for [A, B], the requests are [B] and [A]—so whichever completes last restores one of the deleted snippets. Route these mutations through a guarded persistence helper or otherwise disable/serialize them until the returned settings arrive.
Useful? React with 👍 / 👎.
Closes #189.
What
settings.promptSnippets, store-persisted so web mode shares them).@namelists matching snippets above file matches in the existing @-mention popup. Enter/Tab/click replaces the@tokenwith the snippet text. Arrow keys walk from snippets into files.Validation
Store rejects names that aren't one token (1-40 of letters, digits,
.,-,_), empty or >8000-char text, and duplicate names onsettings:set. Disk reads drop bad entries instead of throwing.Tests
electron/test/prompt-snippets.test.js: default, strict rejects, failed set keeps old list, heal on reload.test/composerMention.test.tsx: snippets above files, Enter inserts text, ArrowDown crosses into files.vite build, and the full electron suite (4478/4478) pass. Targeted renderer files pass.Known edge
If a snippet is named like a provider id (e.g.
claude), it appears first while typing@claude task, so Enter inserts the snippet instead of keeping the delegate token.🤖 Generated with Claude Code