Repository navigation
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
Open
johnpagdayawon-spec wants to merge 2 commits into
johnpagdayawon-spec wants to merge 2 commits into
Conversation
…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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:How it works:
set-expressioncontroller command, so the engine retags the control and recalculates every dependent total. A format change is a retag with a newtype.malformed-expression,dependency-cycle,evaluation-failed,non-numeric-formula), it is rolled back and the error is shown.useDocxBindingsnow exposes the controller. Selection tracking and edits live inuseFormulaCell.ts, the tag helpers inbindings/formulaCell.ts.Trying it:
harness/formula-cells.htmlrenders the realDocxEditoron the costs fixture with bindings on, with no form or backend. Build it withnpx webpack --config harness/formula-cells/webpack.config.js, serve theharnessfolder with any static server, and openformula-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.tscovers 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.tsxanduseDocxEditor.spec.tsxpass (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
Related pull requests
None