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">
|
<input id="input" class="hidden-input" type="text" autocomplete="off" aria-hidden="true" tabindex="-1">
|
||||||
|
|
||||||
<div class="input-row">
|
<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">
|
<select id="angleMode">
|
||||||
<option value="deg">Degrees</option>
|
<option value="deg">Degrees</option>
|
||||||
<option value="rad">Radians</option>
|
<option value="rad">Radians</option>
|
||||||
@@ -402,8 +402,10 @@
|
|||||||
|
|
||||||
const keyMap = {
|
const keyMap = {
|
||||||
Enter: { type: 'command', value: 'enter' },
|
Enter: { type: 'command', value: 'enter' },
|
||||||
Backspace: { type: 'edit', value: 'Backspace' },
|
Backspace: { type: 'stackOrEdit', value: 'drop' },
|
||||||
Escape: { type: 'command', value: 'clear' },
|
Delete: { type: 'command', value: 'clear' },
|
||||||
|
Escape: { type: 'cancelEdit' },
|
||||||
|
ArrowRight: { type: 'command', value: 'swap' },
|
||||||
'+': { type: 'command', value: 'add' },
|
'+': { type: 'command', value: 'add' },
|
||||||
'-': { type: 'command', value: 'sub' },
|
'-': { type: 'command', value: 'sub' },
|
||||||
'*': { type: 'command', value: 'mul' },
|
'*': { type: 'command', value: 'mul' },
|
||||||
@@ -451,6 +453,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (action.type === 'cancelEdit') {
|
||||||
|
if (!calc.isEditing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
calc.inputValue = '';
|
||||||
|
calc.isEditing = false;
|
||||||
|
syncInputFromState();
|
||||||
|
render();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (action.type === 'input') {
|
if (action.type === 'input') {
|
||||||
@@ -459,10 +473,12 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.type === 'edit') {
|
if (action.type === 'stackOrEdit') {
|
||||||
if (calc.isEditing) {
|
if (calc.isEditing) {
|
||||||
editXWithKey(action.value);
|
editXWithKey('Backspace');
|
||||||
render();
|
render();
|
||||||
|
} else {
|
||||||
|
execute(action.value);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user