Skip to content

feat(calculator): live expression on top line, paste into expression line#3

Merged
ijbo merged 1 commit into
mainfrom
claude/calculator-paste-live-expr
May 14, 2026
Merged

feat(calculator): live expression on top line, paste into expression line#3
ijbo merged 1 commit into
mainfrom
claude/calculator-paste-live-expr

Conversation

@ijbo
Copy link
Copy Markdown
Contributor

@ijbo ijbo commented May 14, 2026

Summary

Two visible behaviour fixes to the Tools → Calculator template:

  1. Live expression on the top line. While typing (2+3)^4*4, every keystroke now appears on the small top expression line — the in-progress operand was previously missing because show() only rendered the committed chain. The big bottom line continues to show a live partial-evaluation running total.

  2. Paste into the top line works. Pasting (2+3)^4*4 directly onto the small expression line used to concatenate onto the rendered "0", producing "0(2+3)^4*4"Error. The paste handler now routes clipboard text straight into applyPasted (same code path as paste-into-result), evaluating instantly with no follow-up Enter/blur.

  3. Blur dedupe. commitExprEdit early-returns when the line already matches the latest history entry, so the post-paste blur doesn't create a duplicate history row.

Test plan

  • Type (2+3)^4*4 keystroke by keystroke → top line builds up the full expression on every press; bottom shows live partial results (5, then 625, then 2500) once each sub-expression is evaluable
  • Press = → top becomes (2+3)^4*4 =, bottom becomes 2500, single history row created
  • Paste (2+3)^4*4 onto the small expression line → top (2+3)^4*4 =, bottom 2500 immediately
  • Paste 100/(4+1) onto the big result line → top 100/(4+1) =, bottom 20
  • Paste 1,234 × 5 (whitespace + comma + unicode ×) → normalised to 1234*5, evaluates 6170
  • Paste alert(1) → top alert(1) =, bottom Error (still blocked by strict allowlist)
  • After paste, click somewhere to blur the expression line → no duplicate history row appears
  • Calculator-tool Playwright suite (10 cases) + template-loading suite (8 cases) still green locally

🤖 Generated with Claude Code

…line

- Top expression line now shows the full typed expression including the
  current operand, e.g. (2+3)^4*4 — was previously only the committed
  chain (so the in-progress operand was missing while typing)
- Bottom result line shows a live partial-evaluation result on every
  keystroke; falls back to the current operand when the partial is not
  yet valid (half-open bracket, trailing operator)
- Pasting a full expression directly into the small top expression line
  now evaluates immediately — previously the handler appended the pasted
  text onto the rendered "0", producing "0(2+3)^4*4" → Error
- commitExprEdit() dedupes against the latest history entry, so the
  post-paste blur no longer creates a duplicate history row
@ijbo ijbo merged commit fa0f9da into main May 14, 2026
3 of 4 checks 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.

1 participant