Skip to content

Fix error-string center alignment and sync toolbar align state#136

Merged
hackerwins merged 1 commit into
mainfrom
type-align
Apr 18, 2026
Merged

Fix error-string center alignment and sync toolbar align state#136
hackerwins merged 1 commit into
mainfrom
type-align

Conversation

@ggyuchive

@ggyuchive ggyuchive commented Apr 18, 2026

Copy link
Copy Markdown
Member

Summary

  • 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

Why

Linked Issues

Fixes #

Verification

CI automatically posts a verification summary comment on this PR with
per-lane results for both verify:self and verify:integration.

  • verify:self — CI comment shows ✅
  • verify:integration — CI comment shows ✅ (or explicit skip reason below)

Skip reason (if applicable):

Risk Assessment

  • User-facing risk:
  • Data/security risk:
  • Rollback plan:

Notes for Reviewers

  • UI changes (screenshots/gifs if applicable):
  • Follow-up work (if any):

Summary by CodeRabbit

Release Notes

  • New Features

    • Cell alignment now intelligently defaults based on content: error values, dates, and numbers align right; booleans and text align left.
  • Improvements

    • Formatting toolbar now accurately tracks and displays the active cell's effective alignment state.

- 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]>
@coderabbitai

coderabbitai Bot commented Apr 18, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This pull request consolidates horizontal cell alignment logic by extracting a defaultAlign function from gridcanvas.ts into the model layer (worksheet/input.ts), updating consumers to use this centralized implementation, and adding a new public getActiveEffectiveAlign() API to the Spreadsheet class for alignment queries.

Changes

Cohort / File(s) Summary
Repository Configuration
.gitignore
Added pattern to ignore pnpm store directory (.pnpm-store/).
Formula Constants
packages/sheets/src/formula/formula.ts
Extracted error string literals into new exported constant ErrValues, updated ErrNode type to reference it via typeof ErrValues[number].
Module Exports
packages/sheets/src/index.ts
Re-exported defaultAlign utility to make it publicly available from the main package entry point.
Type Refactoring
packages/sheets/src/model/core/types.ts
Reformatted NumberFormat union type from multi-line to single-line definition (no functional change).
Alignment Logic Centralization
packages/sheets/src/model/worksheet/input.ts
Introduced new exported function defaultAlign() that infers horizontal cell alignment based on error values, boolean literals, date format, and numeric content; consolidates alignment rules previously scattered in gridcanvas.ts.
Style Defaults
packages/sheets/src/model/worksheet/style-mutation.ts
Removed al: 'left' default entry from DefaultStyleValues, changing how redundant alignment values are pruned.
Grid Rendering
packages/sheets/src/view/gridcanvas.ts
Removed local defaultAlign() implementation and replaced with import from ../model/worksheet/input, eliminating code duplication.
Spreadsheet API
packages/sheets/src/view/spreadsheet.ts
Added new public async method getActiveEffectiveAlign() to retrieve active cell's effective horizontal alignment, combining explicit style alignment with content-based defaults via defaultAlign().
Toolbar State Management
packages/frontend/src/components/formatting-toolbar.tsx
Introduced dedicated effectiveAlign state variable to track active cell alignment; updated refreshStyle() to concurrently fetch cell style and effective alignment via new getActiveEffectiveAlign() API.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • hackerwins

Poem

🐰 With whiskers twitched and a satisfied hop,
Alignment logic consolidated—no more duplicates to stop!
From scattered gridcanvas to model's embrace,
The defaultAlign function finds its rightful place! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main changes: fixing error-string center alignment and syncing toolbar align state with computed alignment.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch type-align

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Verification: verify:self

Result: ✅ PASS in 119.3s

Lane Status Duration
sheets:build ✅ pass 13.7s
docs:build ✅ pass 7.9s
verify:fast ✅ pass 59.8s
frontend:build ✅ pass 15.5s
verify:frontend:chunks ✅ pass 0.3s
backend:build ✅ pass 4.8s
cli:build ✅ pass 1.8s
verify:entropy ✅ pass 15.4s

Verification: verify:integration

Result: ✅ PASS

@codecov

codecov Bot commented Apr 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.12903% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/sheets/src/model/worksheet/input.ts 16.66% 15 Missing ⚠️
packages/sheets/src/view/spreadsheet.ts 0.00% 11 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c713e9a and caef8ed.

⛔ Files ignored due to path filters (8)
  • packages/frontend/tests/visual/baselines/harness-visual.browser.desktop.dark.png is excluded by !**/*.png
  • packages/frontend/tests/visual/baselines/harness-visual.browser.mobile.dark.png is excluded by !**/*.png
  • packages/frontend/tests/visual/baselines/harness-visual.browser.mobile.png is excluded by !**/*.png
  • packages/frontend/tests/visual/baselines/harness-visual.browser.png is excluded by !**/*.png
  • packages/frontend/tests/visual/baselines/harness-visual.browser.sheet-formula-errors.desktop.dark.png is excluded by !**/*.png
  • packages/frontend/tests/visual/baselines/harness-visual.browser.sheet-formula-errors.mobile.dark.png is excluded by !**/*.png
  • packages/frontend/tests/visual/baselines/harness-visual.browser.sheet-formula-errors.mobile.png is excluded by !**/*.png
  • packages/frontend/tests/visual/baselines/harness-visual.browser.sheet-formula-errors.png is excluded by !**/*.png
📒 Files selected for processing (9)
  • .gitignore
  • packages/frontend/src/components/formatting-toolbar.tsx
  • packages/sheets/src/formula/formula.ts
  • packages/sheets/src/index.ts
  • packages/sheets/src/model/core/types.ts
  • packages/sheets/src/model/worksheet/input.ts
  • packages/sheets/src/model/worksheet/style-mutation.ts
  • packages/sheets/src/view/gridcanvas.ts
  • packages/sheets/src/view/spreadsheet.ts
💤 Files with no reviewable changes (1)
  • packages/sheets/src/model/worksheet/style-mutation.ts

Comment on lines +349 to +363
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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Comment on lines +267 to +270
/**
* `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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
/**
* `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.

@hackerwins
hackerwins merged commit 67d76f3 into main Apr 18, 2026
4 checks passed
@hackerwins
hackerwins deleted the type-align branch April 18, 2026 15:20
@hackerwins hackerwins mentioned this pull request Apr 19, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants