From 26902af54ec75acbac31fe51f939d1445ef78800 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 10 Apr 2021 13:27:25 +0300 Subject: [PATCH] dashboard: allow ctrl+s and ctrl+f to work outside the config editor --- .../dashboard/GuildConfigEditor.vue | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/dashboard/src/components/dashboard/GuildConfigEditor.vue b/dashboard/src/components/dashboard/GuildConfigEditor.vue index 4c3b6e74..f620a293 100644 --- a/dashboard/src/components/dashboard/GuildConfigEditor.vue +++ b/dashboard/src/components/dashboard/GuildConfigEditor.vue @@ -62,6 +62,11 @@ this.editableConfig = this.config || ""; this.loading = false; }, + beforeUnmount() { + if (this.shortcutKeydownListener) { + window.removeEventListener("keydown", this.shortcutKeydownListener); + } + }, data() { return { loading: true, @@ -71,7 +76,8 @@ errors: [], editorWidth: 900, editorHeight: 600, - savedTimeout: null + savedTimeout: null, + shortcutKeydownListener: null, }; }, computed: { @@ -96,16 +102,20 @@ tabSize: 2 }); - this.$refs.aceEditor.editor.commands.addCommand({ - name: 'save', - bindKey: { - win: "Ctrl-S", - mac: "Cmd-S" - }, - exec: editor => { + this.shortcutKeydownListener = (ev: KeyboardEvent) => { + if (ev.ctrlKey && !ev.altKey && ev.key === "s") { + ev.preventDefault(); this.save(); - }, - }); + return; + } + + if (ev.ctrlKey && !ev.altKey && ev.key === "f") { + ev.preventDefault(); + this.$refs.aceEditor.editor.execCommand("find"); + return; + } + }; + window.addEventListener("keydown", this.shortcutKeydownListener); this.fitEditorToWindow(); },