Skip to content

feat: edit formula cells from a formula bar and Cell panel in the document editor - #2072

Open
johnpagdayawon-spec wants to merge 2 commits into
masterfrom
mock/editable-formula-cells
Open

johnpagdayawon-spec wants to merge 2 commits into
masterfrom
mock/editable-formula-cells

Conversation

@johnpagdayawon-spec

Copy link
Copy Markdown
Contributor

Changes

Calculated cells in document tables (bindings with expr=) were locked with no way to see or change their formula. This makes them work like Excel:

  • Formula bar above the page whenever the document has calculated cells. Clicking a calculated cell shows its name, formula and value; double-clicking jumps straight into the formula. Enter applies, Esc cancels.
  • Cell tab on the right rail (the fx button): the cell's value and formula with Reset to original, and its number format: currency, percent, decimal or whole number, decimal places, currency code, and Apply to all rows in this column.
  • On a calculated cell, the locked-content hint now says to edit the formula in the formula bar.

How it works:

  • Edits go through the existing set-expression controller command, so the engine retags the control and recalculates every dependent total. A format change is a retag with a new type.
  • If an edit introduces a new formula error (malformed-expression, dependency-cycle, evaluation-failed, non-numeric-formula), it is rolled back and the error is shown.
  • useDocxBindings now exposes the controller. Selection tracking and edits live in useFormulaCell.ts, the tag helpers in bindings/formulaCell.ts.
  • The bar stays on screen while the document has formulas, so selecting a cell never shifts the page under the second click of a double-click.

Trying it: harness/formula-cells.html renders the real DocxEditor on the costs fixture with bindings on, with no form or backend. Build it with npx webpack --config harness/formula-cells/webpack.config.js, serve the harness folder with any static server, and open formula-cells.html. A test form with a proposal template is set up in the Lemonade org ("Formula cells test") and will show this once a release includes it.

Tests: new bindings/tests/formulaCell.spec.ts covers finding a formula by tag, column scope, retagging an expression or format, reversing a retag, expression validation and detecting newly introduced errors. formulaCell.spec.ts, useDocxBindings.spec.tsx and useDocxEditor.spec.tsx pass (30 tests); lint and typecheck pass. Checked by hand in the harness: selecting a total, double-click to edit, applying a new formula (dependent totals and prose recalculate), reset to original, and the format controls.

Not in this PR: formulas keep the engine's existing syntax (mul, sum, sub, named references); Excel-style + - * / would need engine work.

Checklist before requesting a review

  • Cleaned up debug prints, comments, and unused code
  • Tested end to end (verified in the local harness; not yet in a live form, which needs a release)
  • Included screenshots or walkthrough video of change if impacts UX

Related pull requests

None

…ument editor

Calculated table cells in the document editor were locked with no way to see
or change their formula. Clicking one now shows its formula in a formula bar
above the page, like Excel, and double-clicking jumps straight into it.
Applying a formula retags the cell through the existing set-expression command,
so every dependent total recalculates; a formula the engine rejects is rolled
back and its error shown.

A Cell tab on the right rail shows the cell's value and formula, with reset to
the template's original, and sets its number format: currency, percent,
decimal or whole number, decimal places and currency code, for one cell or the
whole column.

The formula bar stays on screen whenever the document has calculated cells, so
selecting a cell never shifts the page under a double-click. On calculated
cells the locked-content hint now points to the formula bar.

harness/formula-cells.html renders the real editor on the costs fixture with
bindings on, for trying this without a form or backend.
@johnpagdayawon-spec
johnpagdayawon-spec requested a review from a team as a code owner December 2, 2026 20:55
While a formula is being edited, dragging across cells in a table inserts
the positional reference (E2:E7, summary!B3, E2:end) at the caret, like
Excel's point mode. Each new drag adds another range after a comma, so
several columns can be summed in one formula.
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