🚀 run plugins with the space key

This commit is contained in:
layyback 2022-04-03 13:30:27 +08:00
parent 91b075a439
commit 9613c24deb

View File

@ -10,12 +10,13 @@
id="search" id="search"
class="main-input" class="main-input"
@input="(e) => changeValue(e)" @input="(e) => changeValue(e)"
@keydown.down="(e) => keydownEvent(e, 1)" @keydown.down="(e) => keydownEvent(e, 'down')"
@keydown.up="(e) => keydownEvent(e, -1)" @keydown.up="(e) => keydownEvent(e, 'up')"
@keydown="e => checkNeedInit(e)" @keydown="e => checkNeedInit(e)"
:value="searchValue" :value="searchValue"
:placeholder="placeholder || 'Hi, Rubick2'" :placeholder="placeholder || 'Hi, Rubick2'"
@keypress.enter="(e) => keydownEvent(e)" @keypress.enter="(e) => keydownEvent(e, 'enter')"
@keypress.space="(e) => keydownEvent(e, 'space')"
@focus="emit('focus')" @focus="emit('focus')"
> >
<template #suffix> <template #suffix>
@ -81,7 +82,7 @@ const emit = defineEmits([
"readClipboardContent", "readClipboardContent",
]); ]);
const keydownEvent = (e, index) => { const keydownEvent = (e, key: string) => {
const { ctrlKey, shiftKey, altKey, metaKey } = e; const { ctrlKey, shiftKey, altKey, metaKey } = e;
const modifiers: Array<string> = []; const modifiers: Array<string> = [];
ctrlKey && modifiers.push("control"); ctrlKey && modifiers.push("control");
@ -95,10 +96,25 @@ const keydownEvent = (e, index) => {
modifiers, modifiers,
}, },
}); });
if(index) { switch (key) {
emit("changeCurrent", index); case "up":
} else { emit("changeCurrent", -1);
!props.currentPlugin.name && emit("choosePlugin"); break;
case "down":
emit("changeCurrent", 1);
break;
case "enter":
if (e.target.value === "" || props.currentPlugin.name) return;
emit("choosePlugin");
break;
case "space":
if (e.target.value === "" || props.currentPlugin.name) return;
if (!opConfig.get().perf.common.space) return;
emit("choosePlugin");
break;
default:
break;
} }
}; };