From f30bdb9946b2c66bae04f074daf9536c00766d29 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Sat, 25 Apr 2026 01:17:32 +0200 Subject: [PATCH] fix: restore edited x value on escape --- samples/dev/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/samples/dev/index.js b/samples/dev/index.js index 81ba3a9..0b92332 100644 --- a/samples/dev/index.js +++ b/samples/dev/index.js @@ -21,6 +21,7 @@ let stackCursor = null; let isMovingStackItem = false; let stackSnapshotBeforeMove = null; let stackViewOffset = 0; +let editRestoreValue = null; function labelFor(command) { return ({ add: '+', sub: '−', mul: '×', div: '÷', pow: 'y^x', recip: '1/x', sqr: 'x²' }[command] || command); @@ -105,9 +106,11 @@ function reactivateEditOnX() { calc.remove(0); calc.inputValue = calc.formatNumber(value); calc.isEditing = true; + editRestoreValue = value; } else { calc.inputValue = ''; calc.isEditing = true; + editRestoreValue = null; } syncInputFromState(); } @@ -217,6 +220,7 @@ function pushEditingValueIfNeeded() { } calc.inputValue = ''; calc.isEditing = false; + editRestoreValue = null; syncInputFromState(); } @@ -351,6 +355,7 @@ function editXWithKey(key) { pushEditingValueIfNeeded(); calc.isEditing = true; calc.inputValue = ''; + editRestoreValue = null; } if (key === 'Backspace') { calc.inputValue = calc.inputValue.slice(0, -1); @@ -359,6 +364,7 @@ function editXWithKey(key) { } if (calc.inputValue === '') { calc.isEditing = false; + editRestoreValue = null; } syncInputFromState(); } @@ -377,6 +383,10 @@ function handleKeydown(event) { if (action.type === 'escapeKey') { if (calc.isEditing) { event.preventDefault(); + if (editRestoreValue !== null) { + calc.push(editRestoreValue); + editRestoreValue = null; + } calc.inputValue = ''; calc.isEditing = false; syncInputFromState();