fix: ignore backspace when the stack is empty

This commit is contained in:
2026-05-15 20:47:19 +02:00
parent d1a1d44577
commit 6444357444
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -5,5 +5,5 @@
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants` - Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands` - Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
- Commands: arithmetic, stack, trigonometry, constants `pi` and `e` - 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` - Exports: browser `window.RpnCalculator`, CommonJS `module.exports`
+2 -1
View File
@@ -162,9 +162,10 @@ function execute(name) {
} else if (name === 'backspace') { } else if (name === 'backspace') {
if (calc.isEditing) { if (calc.isEditing) {
inputToX('Backspace'); inputToX('Backspace');
} else { } else if (calc.isValidIndex(0)) {
calc.remove(0); calc.remove(0);
} }
} else if (name === 'swap') { } else if (name === 'swap') {
pushEditingValueIfNeeded(); pushEditingValueIfNeeded();
if (calc.isValidIndex(1)) { if (calc.isValidIndex(1)) {