feat: add keyboard shortcuts for delete, escape, and swap
This commit is contained in:
+21
-5
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user