From 07a4c533fb0d84316d4dd19d098b51206baaafc2 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Sat, 16 May 2026 23:40:13 +0200 Subject: [PATCH] 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. --- .memory/project.md | 1 + samples/calc-02/index.js | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.memory/project.md b/.memory/project.md index 7b1ebe3..c06bd9d 100644 --- a/.memory/project.md +++ b/.memory/project.md @@ -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 diff --git a/samples/calc-02/index.js b/samples/calc-02/index.js index 517fed7..c4335ea 100644 --- a/samples/calc-02/index.js +++ b/samples/calc-02/index.js @@ -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);