Skip to content

Commit

Permalink
Use VueEasyMDE initialized event instead of setTimeout as proposed by
Browse files Browse the repository at this point in the history
@juliushaertl

Signed-off-by: ben <[email protected]>
  • Loading branch information
Ben-Ro authored and juliusknorr committed Oct 19, 2022
1 parent f01a443 commit 3af54d7
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/components/card/Description.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
ref="markdownEditor"
v-model="description"
:configs="mdeConfig"
@initialized="addKeyListeners"
@update:modelValue="updateDescription"
@blur="saveDescription" />

Expand Down Expand Up @@ -175,35 +176,33 @@ export default {
},
},
methods: {
addKeyListeners() {
this.$refs.markdownEditor.easymde.codemirror.on('keydown', (a, b) => {

if (this.keyExitState === 0 && (b.key === 'Meta' || b.key === 'Alt')) {
this.keyExitState = 1
}
if (this.keyExitState === 1 && b.key === 'Enter') {
this.keyExitState = 0
this.$refs.markdownEditor.easymde.codemirror.off('keydown', undefined)
this.$refs.markdownEditor.easymde.codemirror.off('keyup', undefined)
this.hideEditor()
}
})
this.$refs.markdownEditor.easymde.codemirror.on('keyup', (a, b) => {
if (b.key === 'Meta' || b.key === 'Control') {
this.keyExitState = 0
}

})
},
showEditor() {
if (!this.canEdit) {
return
}
this.descriptionEditing = true
this.description = this.card.description

// Has to start after the Editor is fully loaded. This shouldn't take longer than 1/4 second
setTimeout(() => {
this.$refs.markdownEditor.easymde.codemirror.on('keydown', (a, b) => {

if (this.keyExitState === 0 && (b.key === 'Meta' || b.key === 'Alt')) {
this.keyExitState = 1
}
if (this.keyExitState === 1 && b.key === 'Enter') {
this.keyExitState = 0
this.$refs.markdownEditor.easymde.codemirror.off('keydown', undefined)
this.$refs.markdownEditor.easymde.codemirror.off('keyup', undefined)
this.hideEditor()
}
})
this.$refs.markdownEditor.easymde.codemirror.on('keyup', (a, b) => {
if (b.key === 'Meta' || b.key === 'Control') {
this.keyExitState = 0
}

})
}, 250)

},
hideEditor() {
this.$refs.markdownEditor.easymde.codemirror.off('keydown', undefined)
Expand Down

0 comments on commit 3af54d7

Please sign in to comment.