Fix error-string center alignment and sync toolbar align state#136
Conversation
- Use ErrValues set (single source of truth from formula.ts) instead of a # prefix check, so only real formula errors get center alignment - Add getActiveEffectiveAlign() to Spreadsheet and wire it into the formatting toolbar so the active alignment icon reflects the computed (content-based) alignment, not just the stored al style key - Remove al:'left' from DefaultStyleValues so explicit left-align on number cells is not pruned as redundant - Add .pnpm-store/ to .gitignore Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
📝 WalkthroughWalkthroughThis pull request consolidates horizontal cell alignment logic by extracting a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Verification: verify:selfResult: ✅ PASS in 119.3s
Verification: verify:integrationResult: ✅ PASS |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/sheets/src/model/worksheet/input.ts`:
- Around line 349-363: defaultAlign currently only treats exact 'TRUE'/'FALSE'
and nf === 'date' specially, but inferInput may already detect trimmed/lowercase
booleans and date-like strings; update defaultAlign (the function in input.ts)
to use the result of inferInput: after handling FormulaErrorValues, check
inferred.type === 'boolean' and return 'center', and check inferred.type ===
'date' (or keep nf === 'date' OR inferred.type === 'date') and return 'right'
before falling back to number => 'right' and default 'left', so
imported/un-normalized values like "true" or "2026-04-18" align correctly.
In `@packages/sheets/src/view/spreadsheet.ts`:
- Around line 267-270: Update the doc comment for getActiveEffectiveAlign to
reflect actual behavior for formula errors: change the statement that
"errors/text → left" to indicate that formula errors (ErrValues) are centered
via defaultAlign(), and mention that text still defaults to left while ErrValues
default to center; reference getActiveEffectiveAlign and defaultAlign (and
ErrValues) to locate the code to edit.
🪄 Autofix (Beta)
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
Run ID: f762cd57-e594-4524-9dd3-59bd4b648fb0
⛔ Files ignored due to path filters (8)
packages/frontend/tests/visual/baselines/harness-visual.browser.desktop.dark.pngis excluded by!**/*.pngpackages/frontend/tests/visual/baselines/harness-visual.browser.mobile.dark.pngis excluded by!**/*.pngpackages/frontend/tests/visual/baselines/harness-visual.browser.mobile.pngis excluded by!**/*.pngpackages/frontend/tests/visual/baselines/harness-visual.browser.pngis excluded by!**/*.pngpackages/frontend/tests/visual/baselines/harness-visual.browser.sheet-formula-errors.desktop.dark.pngis excluded by!**/*.pngpackages/frontend/tests/visual/baselines/harness-visual.browser.sheet-formula-errors.mobile.dark.pngis excluded by!**/*.pngpackages/frontend/tests/visual/baselines/harness-visual.browser.sheet-formula-errors.mobile.pngis excluded by!**/*.pngpackages/frontend/tests/visual/baselines/harness-visual.browser.sheet-formula-errors.pngis excluded by!**/*.png
📒 Files selected for processing (9)
.gitignorepackages/frontend/src/components/formatting-toolbar.tsxpackages/sheets/src/formula/formula.tspackages/sheets/src/index.tspackages/sheets/src/model/core/types.tspackages/sheets/src/model/worksheet/input.tspackages/sheets/src/model/worksheet/style-mutation.tspackages/sheets/src/view/gridcanvas.tspackages/sheets/src/view/spreadsheet.ts
💤 Files with no reviewable changes (1)
- packages/sheets/src/model/worksheet/style-mutation.ts
| export function defaultAlign(rawValue: string, nf?: NumberFormat): TextAlign { | ||
| if (FormulaErrorValues.has(rawValue)) { | ||
| return 'center'; | ||
| } | ||
| if (rawValue === 'TRUE' || rawValue === 'FALSE') { | ||
| return 'center'; | ||
| } | ||
| if (nf === 'date') { | ||
| return 'right'; | ||
| } | ||
| const inferred = inferInput(rawValue); | ||
| if (inferred.type === 'number') { | ||
| return 'right'; | ||
| } | ||
| return 'left'; |
There was a problem hiding this comment.
Handle inferred booleans and dates in defaultAlign().
Right now only exact uppercase TRUE/FALSE and nf === 'date' get special handling. Since inferInput() already recognizes lowercase/trimmed booleans and date literals, imported or otherwise un-normalized values like "true" or "2026-04-18" render/show as left-aligned despite the helper’s documented behavior.
🐛 Proposed fix
export function defaultAlign(rawValue: string, nf?: NumberFormat): TextAlign {
if (FormulaErrorValues.has(rawValue)) {
return 'center';
}
- if (rawValue === 'TRUE' || rawValue === 'FALSE') {
- return 'center';
- }
- if (nf === 'date') {
- return 'right';
- }
const inferred = inferInput(rawValue);
+ if (inferred.type === 'boolean') {
+ return 'center';
+ }
+ if (nf === 'date' || inferred.type === 'date') {
+ return 'right';
+ }
if (inferred.type === 'number') {
return 'right';
}
return 'left';
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/sheets/src/model/worksheet/input.ts` around lines 349 - 363,
defaultAlign currently only treats exact 'TRUE'/'FALSE' and nf === 'date'
specially, but inferInput may already detect trimmed/lowercase booleans and
date-like strings; update defaultAlign (the function in input.ts) to use the
result of inferInput: after handling FormulaErrorValues, check inferred.type ===
'boolean' and return 'center', and check inferred.type === 'date' (or keep nf
=== 'date' OR inferred.type === 'date') and return 'right' before falling back
to number => 'right' and default 'left', so imported/un-normalized values like
"true" or "2026-04-18" align correctly.
| /** | ||
| * `getActiveEffectiveAlign` returns the effective horizontal alignment of | ||
| * the active cell, incorporating content-based defaults (numbers/dates → | ||
| * right, booleans → center, errors/text → left) when no explicit al is set. |
There was a problem hiding this comment.
Fix the comment: formula errors are centered, not left-aligned.
The implementation falls through to defaultAlign(), which returns 'center' for ErrValues, so the public API docs currently contradict the behavior.
📝 Proposed comment fix
- * the active cell, incorporating content-based defaults (numbers/dates →
- * right, booleans → center, errors/text → left) when no explicit al is set.
+ * the active cell, incorporating content-based defaults (numbers/dates →
+ * right, booleans/formula errors → center, text → left) when no explicit al is set.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * `getActiveEffectiveAlign` returns the effective horizontal alignment of | |
| * the active cell, incorporating content-based defaults (numbers/dates → | |
| * right, booleans → center, errors/text → left) when no explicit al is set. | |
| /** | |
| * `getActiveEffectiveAlign` returns the effective horizontal alignment of | |
| * the active cell, incorporating content-based defaults (numbers/dates → | |
| * right, booleans/formula errors → center, text → left) when no explicit al is set. |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/sheets/src/view/spreadsheet.ts` around lines 267 - 270, Update the
doc comment for getActiveEffectiveAlign to reflect actual behavior for formula
errors: change the statement that "errors/text → left" to indicate that formula
errors (ErrValues) are centered via defaultAlign(), and mention that text still
defaults to left while ErrValues default to center; reference
getActiveEffectiveAlign and defaultAlign (and ErrValues) to locate the code to
edit.
Summary
Why
Linked Issues
Fixes #
Verification
CI automatically posts a verification summary comment on this PR with
per-lane results for both
verify:selfandverify:integration.Skip reason (if applicable):
Risk Assessment
Notes for Reviewers
Summary by CodeRabbit
Release Notes
New Features
Improvements