Keyboard support #12
Labels
No labels
aira:blocked
aira:cancelled
aira:ci
aira:done
aira:implementing
aira:merging
aira:plan-review
aira:planning
aira:qa
aira:queued
aira:ready
aira:review
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lab/web-calculator#12
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?
Make the calculator fully usable from the keyboard.
Requirements
0-9and.enter numbers;+,-,*,/choose add, subtract, multiply, divide;%chooses percent.Enteror=computes;Escapeclears (likeC);Backspacedeletes the last entered character.Acceptance criteria
1,2,+,3,Entershows15.Escaperesets the display to0.Backspaceturns123into12.*,/,-and%select the matching operations.Aira · queued
Aira picked up this task. Branch
aira/12-keyboard-support.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/12-keyboard-support.T3 thread:
mcp:launch:f0cb46248edbd26b8331d66f0027e85a98f438051c5a62ec324268100e8a9df5Aira · Plan (round 1) at
49e0a054Added docs/plans/issue-12.md (keyboard refactor: handlePadKey, mapKeyboardKey, backspaceEntry, calculator-ui.js extraction, test plan for AC1–4); committed and pushed to aira/12-keyboard-support; npm test green (70 tests).
docs/plans/issue-12.md
Issue #12: Keyboard support
Goal
Make the calculator fully usable from the keyboard. Key presses must use the same UI handlers as on-screen buttons (digits, operators, equals, clear) without duplicating calculation or API logic. Add Backspace to delete the last character of the current entry.
Acceptance criteria
1,2,+,3,Entershows15.Escaperesets the display to0.Backspaceturns123into12.*,/,-and%select the matching operations (multiply, divide, subtract, percent).Design
Refactor: single keypad dispatcher
Replace the inline
if/elsechain in the#keypadclick listener withhandlePadKey(key), wherekeyuses the same values asbutton[data-key]today:key0–9appendDigit.appendDecimal+commitOperand('add')−commitOperand('subtract')×commitOperand('multiply')÷commitOperand('divide')%commitOperand('percent')√applyUnary('sqrt')=evaluate()Creset()data-keyfrom the clicked button and callhandlePadKey(key).event.keyand callhandlePadKey(orbackspaceEntryfor Backspace).Keyboard mapping
Add pure function
mapKeyboardKey(eventKey)(testable in Node):event.key0–9,.,+,%-−*×/÷==Enter=EscapeCBackspace'Backspace'(not a buttondata-key)Return
nullfor unmapped keys. Onkeydown, skip whenctrlKey,metaKey, oraltKeyis set. When a key is handled, callevent.preventDefault().Backspace (new helper)
backspaceEntry():freshEntryis true orentry === '0'.entry; if empty, setentryto'0'.setDisplay(entry)(no API call).Script extraction (
public/calculator-ui.js)Move the inline
<script>fromindex.htmlintopublic/calculator-ui.jsso tests can load the real page logic with a minimal DOM stub:index.htmlloads<script src="calculator-ui.js"></script>only (no inline calculator logic).initCalculatorregistersdocument.addEventListener('keydown', …):mapped === 'Backspace'→backspaceEntry()handlePadKey(mapped)whenmapKeyboardKeyreturns a pad key.Server / calculation layer
No changes to
lib/calculator.jsorserver.js.evaluate()continues to call/api/calculate; keyboardEnter/=only triggershandlePadKey('=').Test layout
test/calculator-ui.test.jsrequireexports; stubdocument/fetch; AC1–4 and backspace behaviour.test/ui.test.jskeydown, sharedhandlePadKey.Files to change
public/calculator-ui.jsmapKeyboardKey,handlePadKey,backspaceEntry,initCalculator, dual browser/Node export.public/index.htmlcalculator-ui.js.test/calculator-ui.test.jstest/ui.test.jsdocs/plans/issue-12.mdNo changes to
lib/calculator.js,server.js,package.json, or CI workflows.Test plan
UI logic (
test/calculator-ui.test.js)Use
node:testwith a minimal DOM stub (#display,#keypad,#history-list,#clear-history) and afetchmock that returns{ result: 15 }fora=12&b=3&op=add.handlePadKey('1'..'3'),'='15mapKeyboardKey('Enter')→handlePadKey('=')15mapKeyboardKey('Escape')→handlePadKey('C')01,2,3;backspaceEntry()12; again →1mapKeyboardKeyfor-,*,/,%−,×,÷,%; after digit + op, internalpendingOpissubtract/multiply/divide/percentmapKeyboardKey('q')nullhandlePadKey('C')0Page (
test/ui.test.js)index.htmlincludescalculator-ui.jscalculator-ui.jsdefineskeydownlistener andmapKeyboardKeyhandlePadKeyused from click handler and keyboard path/api/calculateusage unchangedHTTP (
test/server.test.js)No new tests required; existing add/multiply/etc. cases regress the API used by AC1.
Pre-push
Run
npm testlocally beforegit push origin aira/12-keyboard-support.Risks
handlePadKeylogic equivalent to current click handler; run full test suite.−,×,÷)mapKeyboardKey; explicit AC4 tests.freshEntry)0; document in tests.preventDefaultinterferes with browser shortcutsevaluateasynctest callbacks and awaithandlePadKey('=')ifevaluateis async.Attachment: plan-12-r1.md
Aira · plan review
Plan pushed at
49e0a054; independent Dodik plan review started.Aira · dodik-plan FAIL on
49e0a054The plan's acceptance criteria match the task, and the keypad dispatcher matches the current button handlers and Unicode operator labels. It still fails because all UI logic moves to public/calculator-ui.js while server.js is left unchanged, and that server only serves index.html at / and returns 404 for every other path, so the browser never loads the script.
Checks performed
Attachment: dodik-plan-49e0a054.json
Aira · planning
Dodik rejected the plan; revision round 1.
Aira · Plan (round 2) at
9fd89dbfRevised docs/plans/issue-12.md per Dodik: GET /calculator-ui.js in server.js with HTTP test; initCalculator returns handlePadKey/backspaceEntry/getDisplayText; AC4 via mocked fetch op param; ui.test.js split (markup in index.html, behavior in calculator-ui.js). Committed and pushed.
docs/plans/issue-12.md
Issue #12: Keyboard support
Goal
Make the calculator fully usable from the keyboard. Key presses must use the same UI handlers as on-screen buttons (digits, operators, equals, clear) without duplicating calculation or API logic. Add Backspace to delete the last character of the current entry.
Acceptance criteria
1,2,+,3,Entershows15.Escaperesets the display to0.Backspaceturns123into12.*,/,-and%select the matching operations (multiply, divide, subtract, percent).Design
Refactor: single keypad dispatcher
Replace the inline
if/elsechain in the#keypadclick listener withhandlePadKey(key), wherekeyuses the same values asbutton[data-key]today:key0–9appendDigit.appendDecimal+commitOperand('add')−commitOperand('subtract')×commitOperand('multiply')÷commitOperand('divide')%commitOperand('percent')√applyUnary('sqrt')=evaluate()Creset()data-keyfrom the clicked button and callhandlePadKey(key).event.keyand callhandlePadKey(orbackspaceEntryfor Backspace).Keyboard mapping
Add pure function
mapKeyboardKey(eventKey)(testable in Node):event.key0–9,.,+,%-−*×/÷==Enter=EscapeCBackspace'Backspace'(not a buttondata-key)Return
nullfor unmapped keys. Onkeydown, skip whenctrlKey,metaKey, oraltKeyis set. When a key is handled, callevent.preventDefault().Backspace (new helper)
backspaceEntry():freshEntryis true orentry === '0'.entry; if empty, setentryto'0'.setDisplay(entry)(no API call).Script extraction (
public/calculator-ui.js)Move the inline
<script>fromindex.htmlintopublic/calculator-ui.jsso tests load the same logic the browser runs.Dual-entry pattern:
initCalculatorreturn value (used by Node tests):{ mapKeyboardKey, handlePadKey, backspaceEntry, getDisplayText }. No exposure ofpendingOpon the public test surface.index.htmlloads<script src="calculator-ui.js"></script>only (no inline calculator logic).initCalculatorregistersdoc.addEventListener('keydown', …):mapped === 'Backspace'→backspaceEntry()handlePadKey(mapped)whenmapKeyboardKeyreturns a pad key.HTTP: serve static UI script (
server.js)Today
server.jsonly servesGET /as HTML; any other path (including/calculator-ui.js) returns404JSON. That must change so the extracted script loads in the browser.CALCULATOR_UI = path.join(__dirname, 'public', 'calculator-ui.js')(alongside existingINDEX).GET /calculator-ui.js:200, headerscontent-type: application/javascript; charset=utf-8, bodyfs.readFileSync(CALCULATOR_UI)./health,/api/calculate,/api/history,DELETE /api/history, andGET /unchanged. Unlisted paths still404JSON.lib/calculator.jsis unchanged.evaluate()still calls/api/calculate; keyboardEnter/=only triggershandlePadKey('=').Test layout
test/calculator-ui.test.jsrequireexports; stubdocument/fetch; AC1–4 and backspace behaviour.test/server.test.jsGET /calculator-ui.jsreturns script bytes and JS content type.test/ui.test.jsindex.html; behaviour wiring incalculator-ui.js.Files to change
public/calculator-ui.jsmapKeyboardKey,handlePadKey,backspaceEntry,initCalculator, dual browser/Node export.public/index.htmlcalculator-ui.js.server.jsGET /calculator-ui.jswithapplication/javascriptbody.test/calculator-ui.test.jstest/server.test.jstest/ui.test.jsdocs/plans/issue-12.mdNo changes to
lib/calculator.js,package.json, or CI workflows.Test plan
UI logic (
test/calculator-ui.test.js)Use
node:testwith a minimal DOM stub (#display,#keypad,#history-list,#clear-history).const api = initCalculator(doc)yieldsapi.handlePadKey,api.backspaceEntry,api.getDisplayText,api.mapKeyboardKey.fetchmock: record each request URL; for calculate URLs, return{ result: 15 }whena=12&b=3&op=add, and sensible defaults for historyGET/DELETE.api.handlePadKey('1'..'3'), then'='(await if async)api.getDisplayText()→15api.handlePadKey(api.mapKeyboardKey('Enter'))15api.handlePadKey(api.mapKeyboardKey('Escape'))01,2,3;api.backspaceEntry()twice12, then1-,*,/,%:handlePadKey('5'), thenhandlePadKey(mapKeyboardKey(key)), thenhandlePadKey('2'), then'='op=subtract,op=multiply,op=divide,op=percentrespectively (not internalpendingOp)mapKeyboardKeyfor-,*,/,Enter,Escape,BackspacemapKeyboardKey('q')nullapi.handlePadKey('C')0HTTP (
test/server.test.js)GET /calculator-ui.js200;content-typematchesapplication/javascript; body containshandlePadKey(or distinct marker from file)/,/health, calculate, historyPage (
test/ui.test.js)Read
public/index.htmlfor markup only:data-keybuttons still present<script src="calculator-ui.js">(or equivalent)#history-list,#clear-history, “Clear history”Read
public/calculator-ui.jsfor behaviour wiring (notindex.html):/api/calculate, `commitOperand('subtract'handlePadKey(or dispatcher) routes'C'toreset()— notkey === 'C'regex on HTMLrefreshHistory,/api/history,DELETEfrom clear controlkeydownlistener andmapKeyboardKeyhandlePadKeyused from click path and keyboard pathPre-push
Run
npm testlocally beforegit push origin aira/12-keyboard-support.Risks
handlePadKeylogic equivalent to current click handler; run full test suite./calculator-ui.js/).−,×,÷)mapKeyboardKey; mapping unit tests + AC4 via fetchopparam.freshEntry)0; document in tests.preventDefaultinterferes with browser shortcutsevaluateasynctest callbacks and awaithandlePadKey('=')whenevaluateis async.ui.test.jsregressions grep missing strings in HTMLcalculator-ui.jsper table above.Attachment: plan-12-r2.md
Aira · plan review
Plan pushed at
9fd89dbf; independent Dodik plan review started.Aira · dodik-plan PASS on
9fd89dbfThe plan covers every keyboard requirement with numbered criteria, a dispatcher that matches the current button handlers and Unicode operator keys, and tests that prove display results, operator selection via the calculate query, and the new static script route. Serving public/calculator-ui.js from server.js closes the gap that would have left the page script at 404, and calculation stays in lib/calculator.js.
Checks performed
Attachment: dodik-plan-9fd89dbf.json
Aira · implementing
Plan approved by Dodik at
9fd89dbf. Implementation started.Aira · ci
Ready for review at
8beb7b96(PR #16). Waiting for CI.Implemented keyboard support: public/calculator-ui.js with handlePadKey, mapKeyboardKey, backspaceEntry, keydown wiring; server serves GET /calculator-ui.js; index.html loads external script; tests in calculator-ui.test.js (AC1–4), server.test.js, updated ui.test.js. npm test: 81 pass.
Aira · CI passed on
8beb7b96Aira · review
CI is green on
8beb7b96. Independent Dodik and code review started.Aira · dodik PASS on
8beb7b96Commit
8beb7b96makes the calculator keyboard-usable through the same handlePadKey path as the buttons, with mapKeyboardKey and backspaceEntry covered by tests that fail if that behavior is removed. The full suite passed (81 tests, 0 skipped), and keydown checks against the live API showed 1, 2, +, 3, Enter displays 15, Escape resets to 0, Backspace turns 123 into 12, and *, /, -, and % select multiply, divide, subtract, and percent. The diff is limited to the planned UI, server, and test files; existing assertions were moved with the extracted script rather than weakened, and README did not need a change because it does not describe input behavior.Checks performed
8beb7b96) with docs/plans/issue-12.mdAttachment: dodik-8beb7b96.json
Aira · reviewer FAIL on
8beb7b96Keyboard mappings and the handlePadKey refactor meet issue #12 acceptance criteria and the full npm test suite (81/81) passes, including the new static script route. However, the global keydown listener maps Enter to equals and calls preventDefault without exempting focused buttons, which regresses keyboard activation of Clear history and keypad buttons that worked before the change.
Checks performed
8beb7b96dfAttachment: reviewer-8beb7b96.json
Aira · implementing
reviewer failed on
8beb7b96; sent the findings to the orchestrator (fix round 1/6).Aira · ci
Ready for review at
5ba158a8(PR #16). Waiting for CI.Fixed reviewer finding: global keydown now returns early when event.target is inside a button so Enter/Space can activate focused keypad and Clear history controls; added regression test. npm test: 82 pass.
Aira · CI passed on
5ba158a8Aira · review
CI is green on
5ba158a8. Independent Dodik and code review started.Aira · dodik FAIL on
5ba158a8Keyboard support matches the approved plan and the four acceptance checks when focus is not on a button: the suite passes (82 tests), and the keydown path shows 1, 2, +, 3, Enter as 15, Escape as 0, Backspace on 123 as 12, and -, *, /, % as subtract, multiply, divide, and percent. The follow-up guard returns before mapping whenever the event target is a button, so those same keys are dropped after a click or Tab and the calculator is not fully usable from the keyboard in that state.
Checks performed
5ba158awith origin/main and docs/plans/issue-12.md: script extraction, mapKeyboardKey, GET /calculator-ui.js, and tests stay in scopeAttachment: dodik-5ba158a8.json
Aira · reviewer PASS on
5ba158a8Issue #12 delivers keyboard support by refactoring the inline calculator script into
public/calculator-ui.jswith a sharedhandlePadKeypath for clicks and keydown events,mapKeyboardKeyfor US-layout operator/control keys,backspaceEntry, and a server route for the extracted script. All 82 tests pass, acceptance flows for digits, Enter, Escape, Backspace, and */-/% operators are covered, and live server smoke checks confirm/calculator-ui.jsis served and referenced from/. No correctness, security, or regression defects with concrete impact were identified in the diff.Checks performed
5ba158aAttachment: reviewer-5ba158a8.json
Aira · implementing
dodik failed on
5ba158a8; sent the findings to the orchestrator (fix round 2/6).Aira · ci
Ready for review at
72dd0307(PR #16). Waiting for CI.Narrowed button-focus guard: only Enter and Space skip global keydown so native button activation works; digits/operators/Escape/Backspace still reach handlePadKey. Added test for digit key with focused button. npm test: 83 pass.
Aira · CI passed on
72dd0307Aira · review
CI is green on
72dd0307. Independent Dodik and code review started.Aira · dodik PASS on
72dd0307Keyboard support at
72dd030matches the approved issue #12 plan and all four acceptance criteria. Digits, decimal, operators, percent, Enter, equals, Escape, and Backspace go through mapKeyboardKey and the same handlePadKey or backspaceEntry path as the buttons; GET /calculator-ui.js serves that script. npm test reports 83 passed, 0 failed, and 0 skipped, and a keydown-listener check confirms 1, 2, +, 3, Enter shows 15, Escape resets to 0, Backspace turns 123 into 12, and -, *, /, and % select subtract, multiply, divide, and percent. The diff stays within the planned files, with no skipped or weakened tests and no debug leftovers.Checks performed
Attachment: dodik-72dd0307.json
Aira · reviewer PASS on
72dd0307Issue #12 delivers keyboard support by extracting the existing calculator UI into
public/calculator-ui.jswith a sharedhandlePadKeydispatcher,mapKeyboardKey, andbackspaceEntry, wiring document-levelkeydownwith modifier-key guardrails and targeted Enter/Space deferral when a button is focused, and serving the script viaGET /calculator-ui.js. Logic matches the former inline script for API-backed evaluation; all 83 tests pass including AC1–AC4 and the new static route.Checks performed
72dd0307(calculator-ui.js, index.html, server.js, tests, plan)Attachment: reviewer-72dd0307.json
Aira · qa
Dodik and the reviewer passed on
72dd0307. Preview deployed at http://127.0.0.1:34365; QA started.Aira · qa PASS on
72dd0307Preview commit
72dd0307a2serves a calculator page with the required controls, and keyboard input observed through the served page script against the live API meets every acceptance criterion: 1 2 + 3 Enter and = display 15, Escape resets to 0, Backspace turns 123 into 12, and * / - % select multiply, divide, subtract, and percent via the same calculate requests as the buttons. Invalid input returns 400, and the project tests including key handling all passed.Checks performed
Attachment: qa-72dd0307.json
Aira · merging
QA passed on
72dd0307. Merging.Aira · Merged PR #16
Merge commit
02216ffb7238dbf6d4e5b9a6e834dae5abea8963from reviewed head72dd0307a21853b6d3f18e87f9f1c69a242cd343.72dd030matches the approved issue #12 plan and all four acceptance criteria. Digits, decimal, operators, percent, Enter, equals, Escape, anpublic/calculator-ui.jswith a sharedhandlePadKeydispatcher, `mapKeyboar72dd0307a2serves a calculator page with the required controls, and keyboard input observed through the served page