Skip to content

Keep chart source range in step with inserted and deleted lines - #1738

Merged
aiongg merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h2399-chart-switchrowcolumn-rebuilds-t
Oct 22, 2026
Merged

aiongg merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h2399-chart-switchrowcolumn-rebuilds-t

Conversation

@Silvertree2010

Copy link
Copy Markdown
Contributor

Found while testing crates/engine/src/cmd/sheet.rs:216-238 (rewrite never updates Chart.source); used by crates/engine/src/cmd/insert.rs:849 (chart_switch) (no existing issue): chart.switchRowColumn rebuilds the chart from a stale source range after rows or columns are inserted or deleted.

Cause

rewrite() in sheet.rs fixed series, sparkline and anchor references when rows or columns were inserted or deleted, but never updated Chart.source. chart.switchRowColumn prefers source, so it rebuilt the series from the old, stale range.

Fix

rewrite() now adjusts Chart.source with the same reference adjuster used for the series formulas. If the structural edit deletes the whole source block, the source is cleared, so Switch Row/Column falls back to the block the series span.

Verified

  • Regression test switch_row_column_follows_inserted_and_deleted_lines: fails on main without the fix and passes with it (cargo test -p gridcraft-engine --lib switch_row_column_follows_inserted_and_deleted_lines).
  • cargo xtask ci passes.

Not changed

I did not change chart_switch or how the series references are rewritten. I did not touch the behaviour of charts that have no stored source, such as charts read from a file.

🤖 Generated with Claude Code

Found while testing crates/engine/src/cmd/sheet.rs:216-238 (rewrite never updates Chart.source); used by crates/engine/src/cmd/insert.rs:849 (chart_switch)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@MichaelMuClaude

Copy link
Copy Markdown

Independent verification, since this had no review.

Applied cleanly on current main (46 lines, no conflicts). Reconfirmed "fails without the fix" myself: applied only the new test and it panics exactly as described — chart source stays Sheet1!A1:C3 instead of shifting to Sheet1!A2:C4 after the row insert. Applied the real fix and reran:

  • cargo test -p gridcraft-engine --lib switch_row_column_follows_inserted_and_deleted_lines: pass
  • cargo clippy -p gridcraft-engine --all-targets -- -D warnings: clean
  • cargo fmt --check: clean

Same family of gap as #1711 and #1731, which I also verified today — rewrite()/shift_sheet_features fixing some reference kinds (cells, series, anchors) but missing others (print titles, pivot anchors, now chart source). Worth knowing when sequencing merges, since all three touch the same functions and each applies cleanly only against an unpatched main. Looks ready to merge on its own.

@aiongg
aiongg merged commit 5c1b171 into storytold:main Oct 22, 2026
1 check passed
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.

3 participants