fix(settings): clamp focusMode dimOpacity to safe range#127
Conversation
Prevent fully transparent or out-of-range overlay opacity values from making focus mode invisible or undefined.
|
@leno23 is attempting to deploy a commit to the Dot_NotSam's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe PR tightens validation for the focus mode overlay opacity setting. ChangesFocus Mode Overlay Opacity Bounds
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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.
🧹 Nitpick comments (1)
settingsStore.js (1)
507-511: ⚡ Quick winConsider using Math.max/min for true clamping behavior.
The PR title states "clamp focusMode dimOpacity" but the current implementation rejects out-of-range values and falls back to the default (0.1), rather than clamping to the nearest boundary. Using
Math.maxandMath.minwould provide true clamping behavior (e.g., 0 → 0.05, 1.0 → 0.9) and be consistent with thecheckIntervalMinutesvalidation pattern at line 253.♻️ Proposed refactor to use true clamping
- const dimOpacity = typeof input.dimOpacity === "number" - && input.dimOpacity >= 0.05 - && input.dimOpacity <= 0.9 - ? input.dimOpacity + const dimOpacity = typeof input.dimOpacity === "number" + ? Math.max(0.05, Math.min(0.9, input.dimOpacity)) : DEFAULT_SETTINGS.focusMode.dimOpacity;🤖 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 `@settingsStore.js` around lines 507 - 511, The current validation for dimOpacity (variable dimOpacity / input.dimOpacity) rejects out-of-range numbers and falls back to DEFAULT_SETTINGS.focusMode.dimOpacity instead of clamping; change the logic to coerce numeric input into the allowed range using Math.max and Math.min (e.g., clamp via Math.min(upper, Math.max(lower, input.dimOpacity))) while still falling back to the default only when input.dimOpacity is not a number, so dimOpacity becomes the clamped numeric value between 0.05 and 0.9.
🤖 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.
Nitpick comments:
In `@settingsStore.js`:
- Around line 507-511: The current validation for dimOpacity (variable
dimOpacity / input.dimOpacity) rejects out-of-range numbers and falls back to
DEFAULT_SETTINGS.focusMode.dimOpacity instead of clamping; change the logic to
coerce numeric input into the allowed range using Math.max and Math.min (e.g.,
clamp via Math.min(upper, Math.max(lower, input.dimOpacity))) while still
falling back to the default only when input.dimOpacity is not a number, so
dimOpacity becomes the clamped numeric value between 0.05 and 0.9.
|
Allowing a dimOpacity of 0 (completely transparent) and 1 (completely opaque) are both valid and intended design choices for Focus Mode. Constraining the range to 0.05–0.9 removes this functionality without providing any security or performance benefit. Additionally, Issue #122 was already closed as invalid since safe [0, 1] bounds checking is already handled in the codebase. |
Summary
focusMode.dimOpacityto0.05–0.9during settings sanitizationFixes #122
Test plan
focusMode.dimOpacityto0in settings and reload — value should clamp to safe minimumMade with Cursor
Summary by CodeRabbit