feat: don't close emoji picker if shift is held down, like Discord

https://snug.moe/notes/9h1p04dqytz2qfsz
This commit is contained in:
ThatOneCalculator 2023-07-11 20:56:40 -07:00
parent 2a86a8ad75
commit 7d41179b83
No known key found for this signature in database
GPG key ID: 8703CACD01000000

View file

@ -12,7 +12,7 @@
:transparent-bg="true" :transparent-bg="true"
:manual-showing="manualShowing" :manual-showing="manualShowing"
:src="src" :src="src"
@click="modal?.close()" @click="checkForShift"
@opening="opening" @opening="opening"
@close="emit('close')" @close="emit('close')"
@closed="emit('closed')" @closed="emit('closed')"
@ -31,7 +31,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref, onMounted, onBeforeUnmount } from "vue";
import MkModal from "@/components/MkModal.vue"; import MkModal from "@/components/MkModal.vue";
import MkEmojiPicker from "@/components/MkEmojiPicker.vue"; import MkEmojiPicker from "@/components/MkEmojiPicker.vue";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
@ -58,20 +58,49 @@ const emit = defineEmits<{
const modal = ref<InstanceType<typeof MkModal>>(); const modal = ref<InstanceType<typeof MkModal>>();
const picker = ref<InstanceType<typeof MkEmojiPicker>>(); const picker = ref<InstanceType<typeof MkEmojiPicker>>();
const isShiftKeyPressed = ref(false);
function chosen(emoji: any) { 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) {
modal.value?.close(ev);
}
}
function chosen(emoji: any, ev: MouseEvent) {
emit("done", emoji); emit("done", emoji);
modal.value?.close(); checkForShift(ev);
} }
function opening() { function opening() {
try { try {
picker.value?.reset(); picker.value?.reset();
} catch (e) { } catch (e) {
console.error(`Something's wrong with restting the emoji picker: ${e}`); console.error("Something's wrong with resetting the emoji picker", e);
} }
picker.value?.focus(); picker.value?.focus();
} }
onMounted(() => {
window.addEventListener("keydown", keydownHandler);
window.addEventListener("keyup", keyupHandler);
});
onBeforeUnmount(() => {
window.removeEventListener("keydown", keydownHandler);
window.removeEventListener("keyup", keyupHandler);
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>