From 6444357444918fea80fbec4c6104c592e3bd5038 Mon Sep 17 00:00:00 2001 From: MatMoul Date: Fri, 15 May 2026 20:47:19 +0200 Subject: [PATCH] fix: ignore backspace when the stack is empty --- .memory/state.md | 2 +- samples/calc-02/index.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.memory/state.md b/.memory/state.md index a3839b9..389d398 100644 --- a/.memory/state.md +++ b/.memory/state.md @@ -5,5 +5,5 @@ - Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants` - Config: `maxSize`, `base`, `angleMode`, `enabledCommands` - Commands: arithmetic, stack, trigonometry, constants `pi` and `e` -- Demo actions: paste now parses clipboard text as a number before pushing it to the stack; Ctrl+V is supported via the hidden input paste event +- Demo actions: paste now parses clipboard text as a number before pushing it to the stack; Ctrl+V is supported via the hidden input paste event; backspace is ignored when the stack is empty - Exports: browser `window.RpnCalculator`, CommonJS `module.exports` diff --git a/samples/calc-02/index.js b/samples/calc-02/index.js index 169da61..53d168b 100644 --- a/samples/calc-02/index.js +++ b/samples/calc-02/index.js @@ -162,9 +162,10 @@ function execute(name) { } else if (name === 'backspace') { if (calc.isEditing) { inputToX('Backspace'); - } else { + } else if (calc.isValidIndex(0)) { calc.remove(0); } + } else if (name === 'swap') { pushEditingValueIfNeeded(); if (calc.isValidIndex(1)) {