From 2ba6e1db4e2b70da87202c111e55e24988e1e562 Mon Sep 17 00:00:00 2001 From: codex-bot Date: Wed, 9 Sep 2026 16:18:39 +0100 Subject: [PATCH] 1.7-hotfix-1: back button exits app; calc state machine fixes - remove onBackPress interception (was swallowing back press to fake-confirm) - '=' with no pending op no longer zeroes the display (AC + 2 + = was 0) - AC no longer leaves stale fresh flag (first digit after AC appended to 0) - leading zero replaced by first digit (00 + 2 was 002) - operators auto-evaluate pending op (2+3x4 = 20, left-to-right) - repeated = re-applies last operation (2+3=== -> 11) - stale test updated to current list UI bindings --- src/manifest.json | 4 +-- src/pages/index/index.ux | 55 +++++++++++++++++++++++++++------------- tests/calculator.cjs | 15 +++++++---- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/manifest.json b/src/manifest.json index 448a2d7..2c05fb1 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,8 +2,8 @@ "package": "com.example.hellovela", "name": "Calc", "icon": "/common/icon.png", - "versionName": "1.7", - "versionCode": 8, + "versionName": "1.7-hotfix-1", + "versionCode": 9, "minAPILevel": 1, "deviceTypeList": [ "watch" diff --git a/src/pages/index/index.ux b/src/pages/index/index.ux index f1fa7ee..a7dd63f 100644 --- a/src/pages/index/index.ux +++ b/src/pages/index/index.ux @@ -28,6 +28,7 @@ export default { this.ITEM_H = 54 this.KEYS_H = 300 this.PAD = this.KEYS_H / 2 - this.ITEM_H / 2 // 123px spacers so first/last item can center + this.fresh = false }, onScroll(e) { // focused item = the one centered in the list's viewport (spacers included in offset) @@ -39,26 +40,48 @@ export default { this.press(this.keys[this.focused].label) }, press(key) { - if (key === '+') { this.stored = Number(this.display); this.op = '+'; this.fresh = true } - else if (key === '-') { this.stored = Number(this.display); this.op = '-'; this.fresh = true } - else if (key === 'x') { this.stored = Number(this.display); this.op = 'x'; this.fresh = true } - else if (key === '/') { this.stored = Number(this.display); this.op = '/'; this.fresh = true } - else if (key === '=') { - const b = Number(this.display) - let r = 0 - if (this.op === '+') r = this.stored + b - else if (this.op === '-') r = this.stored - b - else if (this.op === 'x') r = this.stored * b - else if (this.op === '/') r = b === 0 ? NaN : this.stored / b - this.display = Number.isFinite(r) ? String(Math.round(r * 1e9) / 1e9) : 'Error' + if (key === '+' || key === '-' || key === 'x' || key === '/') { + // auto-equals: if an operator is already pending and the user typed a number, fold it in first + if (this.op && !this.fresh) { + const b = Number(this.display) + let r = b + if (this.op === '+') r = this.stored + b + else if (this.op === '-') r = this.stored - b + else if (this.op === 'x') r = this.stored * b + else if (this.op === '/') r = b === 0 ? NaN : this.stored / b + this.display = Number.isFinite(r) ? String(Math.round(r * 1e9) / 1e9) : 'Error' + } + this.stored = Number(this.display) + this.op = key this.fresh = true } - else if (key === 'AC') { this.display = '0'; this.stored = 0; this.op = ''; this.fresh = true } + else if (key === '=') { + const b = Number(this.display) + let r = b + if (this.op) { + if (this.op === '+') r = this.stored + b + else if (this.op === '-') r = this.stored - b + else if (this.op === 'x') r = this.stored * b + else if (this.op === '/') r = b === 0 ? NaN : this.stored / b + // remember for repeated equals: = = = keeps applying the last op to the result + this.lastB = b + this.lastOp = this.op + } else if (this.lastOp) { + if (this.lastOp === '+') r = b + this.lastB + else if (this.lastOp === '-') r = b - this.lastB + else if (this.lastOp === 'x') r = b * this.lastB + else if (this.lastOp === '/') r = this.lastB === 0 ? NaN : b / this.lastB + } + this.display = Number.isFinite(r) ? String(Math.round(r * 1e9) / 1e9) : 'Error' + this.op = '' + this.fresh = true + } + else if (key === 'AC') { this.display = '0'; this.stored = 0; this.op = ''; this.fresh = false } else if (key === '+/-') { this.display = this.display.startsWith('-') ? this.display.slice(1) : '-' + this.display } else if (key === '%') { this.display = String(Number(this.display) / 100) } else if (key === '.') { if (this.fresh) { this.display = '0.'; this.fresh = false } else if (!this.display.includes('.')) this.display += '.' } else { - if (this.fresh) { this.display = key; this.fresh = false } + if (this.fresh || this.display === '0') { this.display = key; this.fresh = false } else if (this.display.replace(/[-.]/g,'').length < 9) this.display += key } // keep the focused item visually centered after each press @@ -68,10 +91,6 @@ export default { behavior: 'smooth' }) }, - onBackPress() { - this.confirmKey() - return true - } }