feat: add keyboard shortcuts for delete, escape, and swap

This commit is contained in:
2026-04-24 22:01:22 +02:00
parent 02e68dc1c7
commit dbe046a194
+21 -5
View File
@@ -213,7 +213,7 @@
<input id="input" class="hidden-input" type="text" autocomplete="off" aria-hidden="true" tabindex="-1">
<div class="input-row">
<div class="hint">Keyboard works globally: digits, numpad, Enter, Backspace, +, -, *, /, %, ^</div>
<div class="hint">Keyboard works globally: digits, numpad, Enter, Backspace, Delete, →, +, -, *, /, %, ^</div>
<select id="angleMode">
<option value="deg">Degrees</option>
<option value="rad">Radians</option>
@@ -402,8 +402,10 @@
const keyMap = {
Enter: { type: 'command', value: 'enter' },
Backspace: { type: 'edit', value: 'Backspace' },
Escape: { type: 'command', value: 'clear' },
Backspace: { type: 'stackOrEdit', value: 'drop' },
Delete: { type: 'command', value: 'clear' },
Escape: { type: 'cancelEdit' },
ArrowRight: { type: 'command', value: 'swap' },
'+': { type: 'command', value: 'add' },
'-': { type: 'command', value: 'sub' },
'*': { type: 'command', value: 'mul' },
@@ -451,6 +453,18 @@
}
try {
if (action.type === 'cancelEdit') {
if (!calc.isEditing) {
return;
}
event.preventDefault();
calc.inputValue = '';
calc.isEditing = false;
syncInputFromState();
render();
return;
}
event.preventDefault();
if (action.type === 'input') {
@@ -459,10 +473,12 @@
return;
}
if (action.type === 'edit') {
if (action.type === 'stackOrEdit') {
if (calc.isEditing) {
editXWithKey(action.value);
editXWithKey('Backspace');
render();
} else {
execute(action.value);
}
return;
}