3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Fix Ctrl+S in the config editor trying to save each config you've viewed in the tab

This commit is contained in:
Dragory 2021-05-22 20:44:15 +03:00
parent 64d6bb81fe
commit 553fb57c46
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -37,6 +37,8 @@
import AceEditor from "vue2-ace-editor";
let editorKeybindListener;
export default {
components: {
AceEditor,
@ -62,10 +64,12 @@
this.editableConfig = this.config || "";
this.loading = false;
},
beforeUnmount() {
if (this.shortcutKeydownListener) {
window.removeEventListener("keydown", this.shortcutKeydownListener);
beforeRouteLeave(to, from, next) {
if (editorKeybindListener) {
window.removeEventListener("keydown", editorKeybindListener);
editorKeybindListener = null;
}
next();
},
data() {
return {
@ -77,7 +81,6 @@
editorWidth: 900,
editorHeight: 600,
savedTimeout: null,
shortcutKeydownListener: null,
};
},
computed: {
@ -107,7 +110,12 @@
const nonModKeyPressed = (ev: KeyboardEvent) => (isMac ? ev.ctrlKey : ev.metaKey);
const shortcutModifierPressed = (ev: KeyboardEvent) => modKeyPressed(ev) && !nonModKeyPressed(ev) && !ev.altKey;
this.shortcutKeydownListener = (ev: KeyboardEvent) => {
if (editorKeybindListener) {
// Make sure we clean up any potentially leftover event listeners
window.removeEventListener("keydown", editorKeybindListener);
}
editorKeybindListener = (ev: KeyboardEvent) => {
if (shortcutModifierPressed(ev) && ev.key === "s") {
ev.preventDefault();
this.save();
@ -120,7 +128,7 @@
return;
}
};
window.addEventListener("keydown", this.shortcutKeydownListener);
window.addEventListener("keydown", editorKeybindListener);
this.fitEditorToWindow();
},