Skip to content

Commit

Permalink
add key bind / to search
Browse files Browse the repository at this point in the history
  • Loading branch information
tachibana-shin committed Nov 6, 2022
1 parent 3cabcac commit a4882df
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/BrtPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1657,12 +1657,12 @@ function skipOpening() {
))
)
}
import {checkContentEditable} from "src/helpers/checkContentEditable"
useEventListener(window, "keydown", (event: KeyboardEvent) => {
switch (event.code) {
case "Space": {
if (
(event.target as HTMLElement | undefined)?.nodeName !== "TEXTAREA" &&
(event.target as HTMLElement | undefined)?.nodeName !== "INPUT"
!checkContentEditable(event.target as HTMLElement | null)
)
event.preventDefault()
const playing = artPlaying.value
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/checkContentEditable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

const tags = ["INPUT", "TEXTAREA"]

export function checkContentEditable (el?: HTMLElement | null): boolean {
if (!el) return false

return tags.includes(el.tagName)
}
15 changes: 15 additions & 0 deletions src/layouts/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@focus="focusing = true"
@blur="focusing = false"
@keydown.stop
ref="inputSearchRef"
>
<template v-slot:append>
<q-separator vertical inset class="bg-[rgba(153,153,153,0.3)]" />
Expand Down Expand Up @@ -1102,6 +1103,20 @@ const tabMenuAccountActive = ref<"normal" | "locale" | "setting">("normal")
watch(showMenuAccount, (val) => {
if (val) tabMenuAccountActive.value = "normal"
})
// key bind
import { useEventListener } from "@vueuse/core"
import {checkContentEditable } from "src/helpers/checkContentEditable"
const inputSearchRef = ref<QInput>()
useEventListener(window, "keypress", event => {
if (checkContentEditable(document.activeElement)) return
if (event.code === 'Slash') {
event.preventDefault()
inputSearchRef.value?.focus()
}
})
</script>
<style lang="scss">
Expand Down

0 comments on commit a4882df

Please sign in to comment.