fix: persist edited command pattern value on blur/Enter #11412
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.
Related GitHub Issue
Closes: #11411
Description
This PR attempts to address Issue #11411. Feedback and guidance are welcome.
Problem: In
CommandPatternSelector, when a user edits a command pattern suggestion and then presses Enter or clicks away (blur), the edited value resets to the original pattern. This means when they subsequently click the allow/deny button, the original pattern is sent instead of their edit.Root cause: The
setEditStatehelper usedvalue ?? patternas the stored value. When blur/Enter calledsetEditState(item.pattern, false)without an explicitvalue, it fell back to the originalpatternkey, discarding the edit.Fix: Changed the default in the functional state updater from
value ?? patterntovalue ?? prev[pattern]?.value ?? pattern. This means:valueis omitted (blur/Enter), the current edited value from state is preservedvalueis explicitly passed as the original pattern (Escape), it correctly revertsvalueis explicitly set (onChange), it updates normallyThis ensures the edited command prefix is actually consumed when the user clicks accept/deny, which is the specific concern raised in the issue comments.
Test Procedure
npx vitest run src/components/chat/__tests__/CommandPatternSelector.spec.tsx-- all 14 tests pass (9 existing + 5 new)npx vitest run src/components/chat/__tests__/CommandExecution.spec.tsx-- all 29 tests passNew tests added:
onAllowPatternChangeafter the user blurs then clicks allowPre-Submission Checklist
Documentation Updates
Additional Notes
The fix is a single-line change in
setEditStateinsideCommandPatternSelector.tsx. The key insight is using a functional state updater that reads the current value from state (prev[pattern]?.value) rather than falling back to the original pattern key when no explicit value is provided.