From 45351faeaea6ad4af8280da6c0ec1b4ded0f86fe Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Sat, 27 Feb 2021 18:29:47 +0100 Subject: [PATCH] feat(UI): esc key to cancel cell edit --- src/renderer/components/BaseConfirmModal.vue | 11 +++++++++++ src/renderer/components/WorkspaceQueryTableRow.vue | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/renderer/components/BaseConfirmModal.vue b/src/renderer/components/BaseConfirmModal.vue index 09b3e6ac..f7c2e569 100644 --- a/src/renderer/components/BaseConfirmModal.vue +++ b/src/renderer/components/BaseConfirmModal.vue @@ -74,6 +74,12 @@ export default { else return ''; } }, + created () { + window.addEventListener('keydown', this.onKey); + }, + beforeDestroy () { + window.removeEventListener('keydown', this.onKey); + }, methods: { confirmModal () { this.$emit('confirm'); @@ -82,6 +88,11 @@ export default { hideModal () { this.$emit('hide'); + }, + onKey (e) { + e.stopPropagation(); + if (e.key === 'Escape') + this.hideModal(); } } }; diff --git a/src/renderer/components/WorkspaceQueryTableRow.vue b/src/renderer/components/WorkspaceQueryTableRow.vue index b037a199..163b1d67 100644 --- a/src/renderer/components/WorkspaceQueryTableRow.vue +++ b/src/renderer/components/WorkspaceQueryTableRow.vue @@ -336,6 +336,8 @@ export default { editON (event, content, field) { if (!this.isEditable) return; + window.addEventListener('keydown', this.onKey); + const type = this.fields[field].type.toUpperCase(); ; this.originalContent = content; this.editingType = type; @@ -380,6 +382,8 @@ export default { this.isInlineEditor = { ...this.isInlineEditor, ...obj }; }, editOFF () { + if (!this.editingField) return; + this.isInlineEditor[this.editingField] = false; let content; if (!BLOB.includes(this.editingType)) { @@ -405,6 +409,7 @@ export default { this.editingType = null; this.editingField = null; + window.removeEventListener('keydown', this.onKey); }, hideEditorModal () { this.isTextareaEditor = false; @@ -446,6 +451,14 @@ export default { if (keyName.includes('.')) return this.keyUsage.find(key => key.field === keyName.split('.').pop()); return this.keyUsage.find(key => key.field === keyName); + }, + onKey (e) { + e.stopPropagation(); + if (e.key === 'Escape') { + this.isInlineEditor[this.editingField] = false; + this.editingField = null; + window.removeEventListener('keydown', this.onKey); + } } } };