From f01a4433ede5d35b6697d2a3e8168f7ca452cb41 Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 30 Apr 2022 23:17:49 +0200 Subject: [PATCH 1/2] CTRL/CMD + ENTER to Save Changes on Card Description - fixes nextcloud/deck#3268 Signed-off-by: ben --- src/components/card/Description.vue | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/card/Description.vue b/src/components/card/Description.vue index 3d05db44a..951327623 100644 --- a/src/components/card/Description.vue +++ b/src/components/card/Description.vue @@ -115,6 +115,7 @@ export default { }, data() { return { + keyExitState: 0, description: '', markdownIt: null, descriptionEditing: false, @@ -180,8 +181,33 @@ export default { } 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) + this.$refs.markdownEditor.easymde.codemirror.off('keyup', undefined) this.descriptionEditing = false }, showAttachmentModal() { From 3af54d7186a74550debb05792115dc28a687c733 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 2 May 2022 21:45:24 +0200 Subject: [PATCH 2/2] Use VueEasyMDE `initialized` event instead of setTimeout as proposed by @juliushaertl Signed-off-by: ben --- src/components/card/Description.vue | 43 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/components/card/Description.vue b/src/components/card/Description.vue index 951327623..a40895595 100644 --- a/src/components/card/Description.vue +++ b/src/components/card/Description.vue @@ -60,6 +60,7 @@ ref="markdownEditor" v-model="description" :configs="mdeConfig" + @initialized="addKeyListeners" @update:modelValue="updateDescription" @blur="saveDescription" /> @@ -175,6 +176,26 @@ 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 @@ -182,28 +203,6 @@ export default { 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)