From f01a4433ede5d35b6697d2a3e8168f7ca452cb41 Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 30 Apr 2022 23:17:49 +0200 Subject: [PATCH] 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() {