fix: resolve 4 bugs in termui - #3601
Conversation
📝 WalkthroughWalkthroughThe change updates calculator NaN validation, changes the form clear shortcut to Ctrl+C, and makes confirmation prompts treat truthy defaults as affirmative. ChangesCalculator validation
Form shortcut handling
Confirmation default hint
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/forms-and-validation/src/index.tsx`:
- Around line 125-127: Update the Ctrl+C branch in the widget’s key-event
handler to call this.markDirty() immediately after this.modal.show() and before
returning, ensuring this state-mutating path follows the widget dirty-state
guideline.
- Around line 125-127: Reorder the key handling in the event handler so the
clear-form Ctrl+C condition executes before the quit branch, and update the quit
condition to respond only to q. Preserve the modal display and handled-event
return behavior for Ctrl+C, while ensuring plain c is not treated as clear-form
input.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 72e70c7d-88a6-4c4b-9f28-e4da61181c44
📒 Files selected for processing (3)
examples/calculator/src/index.tsxexamples/forms-and-validation/src/index.tsxpackages/ui/src/prompts.ts
| if (event.key === 'c' && event.ctrl !) { | ||
| this.modal.show(); | ||
| return true; |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Mark the widget dirty after showing the modal.
This branch changes widget state and returns without calling this.markDirty(). Add the call after this.modal.show().
As per coding guidelines: Every state-mutating method on a widget calls this.markDirty().
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@examples/forms-and-validation/src/index.tsx` around lines 125 - 127, Update
the Ctrl+C branch in the widget’s key-event handler to call this.markDirty()
immediately after this.modal.show() and before returning, ensuring this
state-mutating path follows the widget dirty-state guideline.
Source: Coding guidelines
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Handle Ctrl+C before the quit branch.
Line 121 returns false for Ctrl+C, so execution never reaches this modal branch. Plain c then falls through and is inserted into the active field.
Move the clear-form check before the quit check, and reserve the quit check for q.
Proposed fix
- if (event.key === 'q' || (event.ctrl && event.key === 'c')) {
- return false;
- }
-
- if (event.key === 'c' && event.ctrl !) {
+ if (event.key === 'c' && event.ctrl) {
this.modal.show();
return true;
}
+
+ if (event.key === 'q') {
+ return false;
+ }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@examples/forms-and-validation/src/index.tsx` around lines 125 - 127, Reorder
the key handling in the event handler so the clear-form Ctrl+C condition
executes before the quit branch, and update the quit condition to respond only
to q. Preserve the modal display and handled-event return behavior for Ctrl+C,
while ensuring plain c is not treated as clear-form input.
Description
This PR fixes real bugs found in the codebase:
x === trueis equivalent tox(andx === falseto!x), and shorter to read.trim()to''misses whitespace-only input;.trim().length === 0is explicit.isNaNwithNumber.isNaN: the global version coerces its argument, soisNaN('1')returns false whileNumber.isNaNis strict.x === trueis equivalent tox(andx === falseto!x), and shorter to read.Type of Change
How Has This Been Tested?
Checklist
Related Issue
Ref: #3600
Summary by CodeRabbit