res-sheets: embed core/lib/edit for formula editing (scroll, undo, syntax highlight) #16
Labels
No labels
harness
proj-core-console
proj-core-demo
proj-core-edit
proj-core-init
proj-core-lib
proj-core-login
proj-core-res
proj-core-sh
proj-core-theme
proj-docs
proj-extra-calc
proj-extra-code
proj-extra-playbook
proj-extra-sheets
proj-harness
proj-os
residual
tier-0-trivial
tier-1-easy
tier-2-medium
tier-3-hard
tier-4-major
tier-5-epic
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
residual/.agent#16
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?
Problem
The formula entry bar in res-sheets renders the full buffer with no horizontal scrolling. When a cell contains a long formula (e.g. the prime-factorization lambda in
extra/test-eval.txt), the text overflows the terminal width — the cursor becomes invisible and the formula is unreadable.Additionally, the edit mode has no undo/redo, no copy/paste within the buffer, and no syntax highlighting. The hand-rolled key handling duplicates logic that
core/lib/editalready solves.Current behavior (
extra/lib/sheets/tui/view.go:142-154):renderEditBuffer()concatenatesbefore + cursor + afterwith no viewport clamping.Solution
Embed
core/lib/edit.Editorinto the res-sheets TUI for formula editing, following the pattern established byres-code(extra/internal/code/).core/lib/edit.Editoris atea.Modelthat already handles horizontal/vertical scrolling, cursor visibility, undo/redo, and syntax highlighting. Theres-codeembedding recipe demonstrates: hide status bar, size each frame, forward key events, render viaView().Phased approach
Phase 1 — Quick win: horizontal scroll for existing entry bar
Add a scroll offset to
renderEditBuffer()so the cursor stays visible. Minimal change, immediate fix.editScroll intfield toModeleditBuf[editScroll:]inrenderEditBuffer()and clamp to terminal widtheditScrollinupdateEdit()when cursor movesenterEdit()Phase 2 — Full editor embedding
Replace
editBuf/editPoswith an embedded*edit.Editor:enterEdit(): create editor,SetContent(raw), hide status barupdateEdit(): forward keys viae.Update(msg), commit on Enter, cancel on EscrenderEditBuffer():e.SetSize(width, 1); return e.View()core/lib/edit(already used byextra/viares-code)Gives: horizontal scrolling, undo/redo (
Ctrl+Z/Ctrl+Y), syntax highlighting, cursor visibility.Files to modify
extra/lib/sheets/tui/model.goeditScroll(phase 1); replaceeditBuf/editPoswithformulaEditor *edit.Editor(phase 2)extra/lib/sheets/tui/view.gorenderEditBuffer()with scroll offset (phase 1); delegate toformulaEditor.View()(phase 2)extra/lib/sheets/tui/model_test.goeditBuf/editPosVerification
test-eval.sheet.csv, navigate to B1, press Enter. Cursor should scroll horizontally and stay visible.Ctrl+Z/Ctrl+Yundo/redo within formula edit (phase 2).go test ./...inextra/— no regressions.Design reference
core/lib/edit/— the editor library (SetContent, Content, SetSize, Update, View)extra/internal/code/tabs.go— Tab wrapping patternextra/internal/code/render.go:55-63— editor sizing and renderingextra/internal/code/keys.go:129-139— key forwarding with type assertionRelated
extra/test-eval.txt— the formula that exposed the scrolling bug