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:
@@ -2,6 +2,7 @@
|
||||
- Core engine: `src/rpn-calculator.js`
|
||||
- Reference demo: `samples/calc-02/` (portrait-first HP48GX layout, compact mode/constants popups; Const button comes before Mode in the display row)
|
||||
- Important UI behavior: mode button shows the current angle mode; keyboard focus stays on the hidden input on desktop; clipboard paste is supported
|
||||
- Note: keep scrolling behavior in mind for the calc-02 demo when changing the stack/UI layout
|
||||
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`, `listConstants`, `setConstant`, `removeConstant`, `hasConstant`
|
||||
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
|
||||
- Commands: arithmetic, stack, trigonometry, constants `pi` and `e`; arithmetic includes `root`; constants can be added or removed dynamically through the core API
|
||||
|
||||
@@ -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)) {
|
||||
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