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