Extend outline borders across row/column insertion seam#165
Conversation
Custom borders are stored on individual cells, so the existing range-patch shifting did not handle them — inserting a row inside an outer-bordered range left the new row without left/right borders and visibly broke the outline. After the cell shift, scan the two cells flanking the insertion seam in each populated column (row insert) or row (column insert) and copy the borders that ran continuously across the seam onto the inserted cells. This matches Google Sheets behavior: an outer border on A1:B2 stays connected when a row is inserted between rows 1 and 2. Only populated rows/columns are scanned (via the cell index), so the extra work is bounded by data density, not sheet size.
📝 WalkthroughWalkthroughThis pull request implements border outline extension functionality for the Sheets model. When rows or columns are inserted, border flags from cells adjacent to the insertion seam are propagated onto the newly inserted cells, matching Google Sheets behavior and maintaining visual continuity of outlined ranges. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 122.0s
Verification: verify:integrationResult: ✅ PASS |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/sheets/test/sheet/formatting.test.ts (1)
383-505: Optional: add acount > 1insertion case.A multi-insert variant would further lock in the
index + countseam lookup and inserted-span loop behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/sheets/test/sheet/formatting.test.ts` around lines 383 - 505, Add a test that inserts more than one row/column inside a bordered range to exercise the index+count seam logic: reuse Sheet, MemStore, selectStart/selectEnd, setRangeBorders('outer') then call insertRows(startIndex, count>1) and insertColumns(startIndex, count>1) and assert that (1) the newly inserted span inherits the correct outer-edge borders across all inserted cells (e.g., left-edge for all inserted rows in column X or top-edge for all inserted columns in row Y), (2) no interior top/bottom or left/right borders are spuriously set on those inserted cells, and (3) the original bordered cells after the insertion have been shifted by count with their original borders intact using getStyle to verify both edge cases; place tests near the existing insertRows/insertColumns cases to cover multi-insert behavior.packages/sheets/src/model/worksheet/sheet.ts (1)
1162-1168: Prefer bounded seam ranges overNumber.MAX_SAFE_INTEGER.Clamping to sheet dimensions keeps the query window explicit and avoids relying on store-specific handling of very large bounds.
♻️ Suggested refactor
- const upper = Number.MAX_SAFE_INTEGER; - const beforeRange: Range = axis === 'row' - ? [{ r: index - 1, c: 1 }, { r: index - 1, c: upper }] - : [{ r: 1, c: index - 1 }, { r: upper, c: index - 1 }]; - const afterRange: Range = axis === 'row' - ? [{ r: index + count, c: 1 }, { r: index + count, c: upper }] - : [{ r: 1, c: index + count }, { r: upper, c: index + count }]; + const maxRow = this.dimension.rows; + const maxCol = this.dimension.columns; + const beforeRange: Range = axis === 'row' + ? [{ r: index - 1, c: 1 }, { r: index - 1, c: maxCol }] + : [{ r: 1, c: index - 1 }, { r: maxRow, c: index - 1 }]; + const afterRange: Range = axis === 'row' + ? [{ r: index + count, c: 1 }, { r: index + count, c: maxCol }] + : [{ r: 1, c: index + count }, { r: maxRow, c: index + count }];🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/sheets/src/model/worksheet/sheet.ts` around lines 1162 - 1168, The ranges beforeRange and afterRange use Number.MAX_SAFE_INTEGER as an unbounded upper coordinate; replace that with the worksheet's actual max row/column bounds by clamping using the sheet dimensions (e.g. this.getRowCount()/this.rowCount and this.getColCount()/this.colCount or equivalent accessors on the worksheet) so upper is set to the appropriate max for the current axis; update the creation of beforeRange and afterRange (which use axis, index, count and type Range) to compute upperRow = min(this.maxRows, Number.MAX_SAFE_INTEGER) and upperCol = min(this.maxCols, Number.MAX_SAFE_INTEGER) (or simply use the worksheet maxs) and use those bounded values instead of Number.MAX_SAFE_INTEGER.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/sheets/src/model/worksheet/sheet.ts`:
- Around line 1162-1168: The ranges beforeRange and afterRange use
Number.MAX_SAFE_INTEGER as an unbounded upper coordinate; replace that with the
worksheet's actual max row/column bounds by clamping using the sheet dimensions
(e.g. this.getRowCount()/this.rowCount and this.getColCount()/this.colCount or
equivalent accessors on the worksheet) so upper is set to the appropriate max
for the current axis; update the creation of beforeRange and afterRange (which
use axis, index, count and type Range) to compute upperRow = min(this.maxRows,
Number.MAX_SAFE_INTEGER) and upperCol = min(this.maxCols,
Number.MAX_SAFE_INTEGER) (or simply use the worksheet maxs) and use those
bounded values instead of Number.MAX_SAFE_INTEGER.
In `@packages/sheets/test/sheet/formatting.test.ts`:
- Around line 383-505: Add a test that inserts more than one row/column inside a
bordered range to exercise the index+count seam logic: reuse Sheet, MemStore,
selectStart/selectEnd, setRangeBorders('outer') then call insertRows(startIndex,
count>1) and insertColumns(startIndex, count>1) and assert that (1) the newly
inserted span inherits the correct outer-edge borders across all inserted cells
(e.g., left-edge for all inserted rows in column X or top-edge for all inserted
columns in row Y), (2) no interior top/bottom or left/right borders are
spuriously set on those inserted cells, and (3) the original bordered cells
after the insertion have been shifted by count with their original borders
intact using getStyle to verify both edge cases; place tests near the existing
insertRows/insertColumns cases to cover multi-insert behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cc47566c-9f14-4b3e-9909-2d4d3add7e85
📒 Files selected for processing (6)
docs/design/sheets/sheet-style.mddocs/tasks/README.mddocs/tasks/archive/2026/04/20260428-border-outline-extension-todo.mddocs/tasks/archive/README.mdpackages/sheets/src/model/worksheet/sheet.tspackages/sheets/test/sheet/formatting.test.ts
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
Summary
bt/bl/br/bb) did not extend into rows/columns inserted inside an outer-bordered range, so an outline drawn onA1:B2visibly broke when a row was inserted between rows 1 and 2.Sheet.shiftCells, scan the two cells flanking the insertion seam in each populated column/row and copy borders that were continuous across the seam onto the inserted cells — matching Google Sheets behavior.Test plan
pnpm --filter @wafflebase/sheets test test/sheet/formatting.test.ts— 3 new tests pass (row insert, column insert, insert outside range)pnpm --filter @wafflebase/sheets test— 1207 sheets tests passpnpm verify:fast— sheets 1207 + docs 622 + backend 107 + 60 other, all pass🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests
Documentation