fix: restore edited x value on escape
This commit is contained in:
@@ -21,6 +21,7 @@ let stackCursor = null;
|
|||||||
let isMovingStackItem = false;
|
let isMovingStackItem = false;
|
||||||
let stackSnapshotBeforeMove = null;
|
let stackSnapshotBeforeMove = null;
|
||||||
let stackViewOffset = 0;
|
let stackViewOffset = 0;
|
||||||
|
let editRestoreValue = null;
|
||||||
|
|
||||||
function labelFor(command) {
|
function labelFor(command) {
|
||||||
return ({ add: '+', sub: '−', mul: '×', div: '÷', pow: 'y^x', recip: '1/x', sqr: 'x²' }[command] || 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.remove(0);
|
||||||
calc.inputValue = calc.formatNumber(value);
|
calc.inputValue = calc.formatNumber(value);
|
||||||
calc.isEditing = true;
|
calc.isEditing = true;
|
||||||
|
editRestoreValue = value;
|
||||||
} else {
|
} else {
|
||||||
calc.inputValue = '';
|
calc.inputValue = '';
|
||||||
calc.isEditing = true;
|
calc.isEditing = true;
|
||||||
|
editRestoreValue = null;
|
||||||
}
|
}
|
||||||
syncInputFromState();
|
syncInputFromState();
|
||||||
}
|
}
|
||||||
@@ -217,6 +220,7 @@ function pushEditingValueIfNeeded() {
|
|||||||
}
|
}
|
||||||
calc.inputValue = '';
|
calc.inputValue = '';
|
||||||
calc.isEditing = false;
|
calc.isEditing = false;
|
||||||
|
editRestoreValue = null;
|
||||||
syncInputFromState();
|
syncInputFromState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,6 +355,7 @@ function editXWithKey(key) {
|
|||||||
pushEditingValueIfNeeded();
|
pushEditingValueIfNeeded();
|
||||||
calc.isEditing = true;
|
calc.isEditing = true;
|
||||||
calc.inputValue = '';
|
calc.inputValue = '';
|
||||||
|
editRestoreValue = null;
|
||||||
}
|
}
|
||||||
if (key === 'Backspace') {
|
if (key === 'Backspace') {
|
||||||
calc.inputValue = calc.inputValue.slice(0, -1);
|
calc.inputValue = calc.inputValue.slice(0, -1);
|
||||||
@@ -359,6 +364,7 @@ function editXWithKey(key) {
|
|||||||
}
|
}
|
||||||
if (calc.inputValue === '') {
|
if (calc.inputValue === '') {
|
||||||
calc.isEditing = false;
|
calc.isEditing = false;
|
||||||
|
editRestoreValue = null;
|
||||||
}
|
}
|
||||||
syncInputFromState();
|
syncInputFromState();
|
||||||
}
|
}
|
||||||
@@ -377,6 +383,10 @@ function handleKeydown(event) {
|
|||||||
if (action.type === 'escapeKey') {
|
if (action.type === 'escapeKey') {
|
||||||
if (calc.isEditing) {
|
if (calc.isEditing) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
if (editRestoreValue !== null) {
|
||||||
|
calc.push(editRestoreValue);
|
||||||
|
editRestoreValue = null;
|
||||||
|
}
|
||||||
calc.inputValue = '';
|
calc.inputValue = '';
|
||||||
calc.isEditing = false;
|
calc.isEditing = false;
|
||||||
syncInputFromState();
|
syncInputFromState();
|
||||||
|
|||||||
Reference in New Issue
Block a user