fix: restore edited x value on escape

This commit is contained in:
2026-04-25 01:17:32 +02:00
parent 2857df2c6f
commit f30bdb9946
+10
View File
@@ -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();