Skip to content

Add copy-history button - #107

Merged
klh merged 2 commits into
masterfrom
agent/100
Nov 17, 2026
Merged

klh merged 2 commits into
masterfrom
agent/100

Conversation

@klh

@klh klh commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Closes #100

Summary

  • Add a small, initially disabled Copy button beside the history line, with visible keyboard focus and a one-second “Copied” confirmation.
  • Keep an in-memory session of completed non-repeating expressions and copy oldest-first expression = result lines via navigator.clipboard.writeText, falling back to a temporary selected textarea if unavailable or denied. Always remove the textarea and restore focus; never claim success if both paths fail.
  • Preserve the existing last-expression display and recording rules. AC/full reset and division-by-zero clear the session with existing history; entry clear, editing, memory and square root preserve it.
  • Guard against stale confirmation after a reset during an asynchronous write, and restart the confirmation timer on subsequent copies.

Tests-first sweep

Eleven new matrix tests failed before implementation (the three existing history tests passed). The matrix in docs/TEST-SWEEP.md maps each transition to named tests: clipboard success/missing/rejection/throw, negative and decimal line formatting, repeat/incomplete equals, fallback failures/cleanup/focus, timers, asynchronous reset, and cross-feature state preservation. Updated the accessibility button inventory for the new text-labelled control. No unrelated production bug fixes or dependencies.

Validation

  • node --test tests/history.test.cjs: 14 pass, 0 fail
  • node --test: 370 pass, 0 fail
  • git diff --check: passes

Tests use Node VM DOM/clipboard stubs and deterministic timers; real OS/browser clipboard permissions were not exercised.

Copilot AI balanced review requested due to automatic review settings November 17, 2026 05:33
@klh

klh commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Verified the existing implementation for #100 and added a keyboard regression fix: Enter on the Copy control now retains native button activation instead of dispatching calculator equals. The added test checks that Enter is not prevented and does not change the result.

Latest validation: node --test — 371 pass, 0 fail; git diff --check passes. Clipboard API/fallback behavior is covered with VM stubs; real browser clipboard permissions were not exercised.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The document-level Enter handler overrides the focused Copy button’s native activation, changing the result instead of copying it; this needs a fix and a keyboard regression test.

1 open issue
What changed in this PR

Adds session-history copying to the calculator while preserving the existing last-expression display and history reset rules.

Changes:

  • Adds an initially disabled Copy button with visible keyboard focus and a brief “Copied” confirmation.
  • Copies completed expressions oldest-first using the Clipboard API with a textarea fallback.
  • Adds tests and documentation for formatting, reset behavior, clipboard failures, focus restoration, and confirmation timing.
File Description
tests/​memory.test.cjs Updates the accessible-button inventory for Copy.
tests/​history.test.cjs Tests session copying, fallback behavior, cleanup, and timing.
styles.css Styles the history panel and Copy button focus state.
script.js Records session history and implements copying and confirmation.
README.md Documents copying and session lifetime.
index.html Adds the disabled Copy button beside history.
docs/​TEST-SWEEP.md Documents the copy-history test matrix and validation results.

Review effort: Balanced

Comment thread script.js
}
}

historyCopyButton?.addEventListener('click', async () => {
@klh
klh merged commit 65ffb48 into master Nov 17, 2026
1 check 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.

3 participants