Skip to content

Constrain autofill to a single axis (vertical or horizontal)#82

Merged
hackerwins merged 1 commit into
mainfrom
fix-autofill
Mar 25, 2026
Merged

Constrain autofill to a single axis (vertical or horizontal)#82
hackerwins merged 1 commit into
mainfrom
fix-autofill

Conversation

@ggyuchive

@ggyuchive ggyuchive commented Mar 25, 2026

Copy link
Copy Markdown
Member

Summary

Previously computeAutofillRange created a bounding box that could extend in both row and column directions simultaneously. Now the target is clamped to the dominant axis — whichever direction the drag extends furthest from the source edge — matching Google Sheets behaviour.

Why

Both google sheet and excel supports to autofill vertical or horizontal.
This change will handle number-autofill case easily (future work). It does not just fill repeatly, based on Ordinary Least Squares(OLS).

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

  • Documentation

    • Updated frontend and sheet design documentation to clarify autofill behavior constraints.
  • Bug Fixes

    • Modified autofill (fill-handle) to expand along a single axis (vertical or horizontal) based on drag direction distance, with vertical preferred on ties.
  • Tests

    • Updated autofill test cases to validate single-axis expansion behavior.

@github-actions

github-actions Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Verification: verify:self

Result: ✅ PASS in 104.5s

Lane Status Duration
sheets:build ✅ pass 13.2s
docs:build ✅ pass 5.4s
verify:fast ✅ pass 48.4s
frontend:build ✅ pass 14.8s
verify:frontend:chunks ✅ pass 0.3s
backend:build ✅ pass 4.3s
cli:build ✅ pass 1.8s
verify:entropy ✅ pass 16.2s

Verification: verify:integration

Result: ✅ PASS

Previously computeAutofillRange created a bounding box that could
extend in both row and column directions simultaneously.  Now the
target is clamped to the dominant axis — whichever direction the
drag extends furthest from the source edge — matching Google Sheets
behaviour.  Ties favour vertical.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Mar 25, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The pull request modifies autofill behavior for fill-handle drag operations, constraining expansion to a single dominant axis (vertical or horizontal) rather than allowing unrestricted rectangular expansion. The dominant axis is determined by which direction extends farthest from the source, with ties favoring vertical. Updates span design documentation, core implementation, and test coverage.

Changes

Cohort / File(s) Summary
Design Documentation
docs/design/frontend.md, docs/design/sheet.md
Updated documentation to reflect single-axis autofill constraint behavior, specifying how the dominant axis is selected based on drag distance with vertical-tie preference.
Implementation & Tests
packages/sheets/src/model/worksheet/clipboard.ts, packages/sheets/test/sheet/autofill.test.ts
Modified computeAutofillRange to compute vertical and horizontal distances from target to source edges, select the dominant axis, and clamp non-dominant coordinates. Updated existing test and added new test asserting single-axis filling and tie-breaking behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested reviewers

  • hackerwins

Poem

🐰 Along one axis true, the bunny fills with care,
No diagonal sprawl or rectangular flair!
Vertical wins ties—a rule most fair,
The fill-handle hops with purpose and air. 🎯

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: constraining autofill behavior to a single axis, matching the primary objective throughout the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 fix-autofill

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.

@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.

🧹 Nitpick comments (1)
packages/sheets/test/sheet/autofill.test.ts (1)

42-55: Minor naming inconsistency in test description.

The test name says "vertical wins on tie", but this scenario isn't actually a tie—vertical distance is 2 vs horizontal distance 1. Consider renaming to better reflect what's being tested:

-  it('constrains autofill to single axis (vertical wins on tie)', async () => {
+  it('constrains autofill to single axis (diagonal target)', async () => {

Alternatively, to truly test the tie-breaker behavior, you could use a target where both distances are equal (e.g., { r: 2, c: 2 } for a single-cell source at A1).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/sheets/test/sheet/autofill.test.ts` around lines 42 - 55, The test
titled "constrains autofill to single axis (vertical wins on tie)" is misleading
because the target { r: 3, c: 2 } is not a tie (vertical distance 2 vs
horizontal 1); either rename the test to reflect vertical dominance (e.g.,
"constrains autofill to single axis (vertical wins)"), or change the target to a
true tie (e.g., use sheet.autofill({ r: 2, c: 2 })) so it actually exercises the
tie-breaker; update the test title or the autofill target accordingly in the
it(...) block that constructs Sheet and calls sheet.autofill.
🤖 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/test/sheet/autofill.test.ts`:
- Around line 42-55: The test titled "constrains autofill to single axis
(vertical wins on tie)" is misleading because the target { r: 3, c: 2 } is not a
tie (vertical distance 2 vs horizontal 1); either rename the test to reflect
vertical dominance (e.g., "constrains autofill to single axis (vertical wins)"),
or change the target to a true tie (e.g., use sheet.autofill({ r: 2, c: 2 })) so
it actually exercises the tie-breaker; update the test title or the autofill
target accordingly in the it(...) block that constructs Sheet and calls
sheet.autofill.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 97af10de-867b-4cad-bd67-1ae5c12be89f

📥 Commits

Reviewing files that changed from the base of the PR and between c5b64c5 and 272bae5.

📒 Files selected for processing (4)
  • docs/design/frontend.md
  • docs/design/sheet.md
  • packages/sheets/src/model/worksheet/clipboard.ts
  • packages/sheets/test/sheet/autofill.test.ts

@hackerwins
hackerwins merged commit ed79a4d into main Mar 25, 2026
3 checks passed
@hackerwins
hackerwins deleted the fix-autofill branch March 25, 2026 18:45
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