fix: more reliable not closing emoji picker on shift key
This commit is contained in:
parent
05477ee6b4
commit
5b5f997ecf
2 changed files with 6 additions and 29 deletions
|
@ -195,7 +195,7 @@ const props = withDefaults(
|
|||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
(ev: "chosen", v: string): void;
|
||||
(ev: "chosen", v: string, ev: MouseEvent): void;
|
||||
}>();
|
||||
|
||||
const search = ref<HTMLInputElement>();
|
||||
|
@ -436,7 +436,7 @@ function chosen(emoji: any, ev?: MouseEvent) {
|
|||
}
|
||||
|
||||
const key = getKey(emoji);
|
||||
emit("chosen", key);
|
||||
emit("chosen", key, ev);
|
||||
|
||||
// 最近使った絵文字更新
|
||||
if (!pinned.value.includes(key)) {
|
||||
|
|
|
@ -58,29 +58,16 @@ const emit = defineEmits<{
|
|||
|
||||
const modal = ref<InstanceType<typeof MkModal>>();
|
||||
const picker = ref<InstanceType<typeof MkEmojiPicker>>();
|
||||
const isShiftKeyPressed = ref(false);
|
||||
|
||||
const keydownHandler = (e) => {
|
||||
if (e.key === "Shift") {
|
||||
isShiftKeyPressed.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
const keyupHandler = (e) => {
|
||||
if (e.key === "Shift") {
|
||||
isShiftKeyPressed.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
function checkForShift(ev?: MouseEvent) {
|
||||
if (!isShiftKeyPressed.value) {
|
||||
if (ev?.shiftKey) return;
|
||||
modal.value?.close(ev);
|
||||
}
|
||||
}
|
||||
|
||||
function chosen(emoji: any) {
|
||||
function chosen(emoji: any, ev: MouseEvent) {
|
||||
emit("done", emoji);
|
||||
checkForShift();
|
||||
checkForShift(ev);
|
||||
}
|
||||
|
||||
function opening() {
|
||||
|
@ -91,16 +78,6 @@ function opening() {
|
|||
}
|
||||
picker.value?.focus();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener("keydown", keydownHandler);
|
||||
window.addEventListener("keyup", keyupHandler);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("keydown", keydownHandler);
|
||||
window.removeEventListener("keyup", keyupHandler);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
Loading…
Reference in a new issue