Fix hj shortcuts activating in textarea.

This commit is contained in:
Lukáš Kucharczyk 2020-08-25 17:53:41 +02:00
parent bafb84499e
commit 75f03fdf24
1 changed files with 16 additions and 1 deletions

View File

@ -2,6 +2,7 @@
<textarea <textarea
@keyup.enter="addNote" @keyup.enter="addNote"
v-model="content" v-model="content"
ref="content"
rows="10" rows="10"
placeholder="Start typing something…" placeholder="Start typing something…"
autofocus autofocus
@ -38,9 +39,12 @@ export default {
computed: {}, computed: {},
mounted() { mounted() {
document.addEventListener('keyup', e => { document.addEventListener('keyup', e => {
console.log(e.code)
switch (e.code) { switch (e.code) {
case 'KeyJ': case 'KeyJ':
// only if not in textarea
if (e.target.type === 'textarea') {
return
}
// go down in the list, unless it's the last item // go down in the list, unless it's the last item
this.current = this.current =
this.current === null this.current === null
@ -50,6 +54,10 @@ export default {
: this.current + 1 : this.current + 1
break break
case 'KeyK': case 'KeyK':
// only if not in textarea
if (e.target.type === 'textarea') {
return
}
// go up in the list, unless it's the first item // go up in the list, unless it's the first item
this.current = this.current =
this.current === null this.current === null
@ -58,7 +66,14 @@ export default {
? this.current ? this.current
: this.current - 1 : this.current - 1
break break
case 'KeyC':
this.$refs.content.focus()
break
case 'Delete': case 'Delete':
// only if not in textarea
if (e.target.type === 'textarea') {
return
}
alert(`Delete note #${this.current}?`) alert(`Delete note #${this.current}?`)
break break