mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-12-01 06:17:38 -07:00
feat: ✨ don't close emoji picker if shift is held down, like Discord
https://snug.moe/notes/9h1p04dqytz2qfsz
This commit is contained in:
parent
eb49999d9c
commit
6d461c788a
1 changed files with 34 additions and 5 deletions
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue