fix: preserve full calc-02 stack while limiting display to top 4
Keep the calculator stack unlimited in the demo and only constrain the rendered stack view. Also restore the edit cursor position when pulling a value into the input from the stack.
This commit is contained in:
+11
-12
@@ -120,9 +120,7 @@ function clearStatus() {
|
||||
}
|
||||
|
||||
function normalizeStack() {
|
||||
while (calc.stack.length > 4) {
|
||||
calc.stack.shift();
|
||||
}
|
||||
// Demo display only shows the top 4 stack values; the calculator stack remains unlimited.
|
||||
}
|
||||
|
||||
function getStackLine(indexFromTop) {
|
||||
@@ -159,7 +157,6 @@ function updateCopyButtons() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
normalizeStack();
|
||||
const isPortrait = window.matchMedia('(orientation: portrait)').matches || window.innerWidth <= 860;
|
||||
calculatorEl?.classList.toggle('portrait', isPortrait);
|
||||
calculatorEl?.classList.toggle('landscape', !isPortrait);
|
||||
@@ -520,16 +517,18 @@ leftButton.addEventListener('click', () => {
|
||||
}
|
||||
});
|
||||
downButton.addEventListener('click', () => {
|
||||
if (!calc.isEditing && calc.isValidIndex(0)) {
|
||||
const value = calc.stack[0];
|
||||
calc.remove(0);
|
||||
calc.isEditing = true;
|
||||
calc.inputValue = calc.formatNumber(value);
|
||||
render();
|
||||
focusInput();
|
||||
}
|
||||
if (!calc.isEditing && calc.isValidIndex(0)) {
|
||||
const value = calc.stack[0];
|
||||
calc.remove(0);
|
||||
calc.isEditing = true;
|
||||
calc.inputValue = calc.formatNumber(value);
|
||||
editCursor = calc.inputValue.length;
|
||||
render();
|
||||
focusInput();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
rightButton.addEventListener('click', () => {
|
||||
if (calc.isEditing) {
|
||||
editCursor = Math.min(calc.inputValue.length, editCursor + 1);
|
||||
|
||||
Reference in New Issue
Block a user