res-sheets Phase 5: positional copy/cut #6
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
residual/.agent#6
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Plan: res-sheets Phase 5 — Positional Copy/Cut Translation
Goal
When cells are copied or cut and pasted elsewhere, update formula references according to their absolute/relative markers and whether the operation is copy or cut.
Scope
Repo:
git.merith.xyz/residual/extraFiles:
extra/lib/sheets/formula_transform.go(new),extra/lib/sheets/tui/model.goDesired behavior
Copy-paste
SUM(A1:A5). Copy A1:B5 and paste 10 rows down → A11:A15=1..5, B11=SUM(A11:A15).Cut-paste (move)
Lua cells
=lua{...}cells are skipped. Inline Lua is too complex to rewrite safely.Implementation
New file:
extra/lib/sheets/formula_transform.goTranslateExpr(expr Expr, dCol, dRow int) Expr— deep copy of AST with relative refs shifted; absolute (AbsCol/AbsRow true) unchanged.TranslateFormula(raw string, dCol, dRow int) (string, error)— parse → TranslateExpr → render.RenderExpr(expr Expr) string— pretty-print AST with precedence-aware parens.RenderRange(rng CellRange) string—From.String() + ":" + To.String().UpdateRefsForMove(sheet *Sheet, srcTL, srcBR, dstTL CellRef) map[CellRef]string— find every formula cell outside the source rectangle whose formula references a cell inside it; translate by move offset preserving markers; return map cell refs → updated raw formulas.Changes to
extra/lib/sheets/tui/model.gocopySelection()already storesCell.Rawfrom Phase 1.pasteClipboard(): compute offsetdCol = cursor.Col - clip.srcTL.Col,dRow = cursor.Row - clip.srcTL.Row; for each clipboard cell, if raw is a formula translate by offset else write raw as-is; ifclip.cutalso callUpdateRefsForMoveand include external-formula updates in samecommitbatch; clear clipboard after a cut.Tests
SUM(A1:A5)down 10 →SUM(A11:A15)); cut updates external absolute refs; cut does not update external relative refs; Lua cells paste verbatim.Verification