Merge pull request #3721 from thelounge/xpaw/fix-3690

Fix escape key handling
This commit is contained in:
Pavel Djundik 2020-01-24 16:08:30 +02:00 committed by GitHub
commit b890e7e976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 9 deletions

View File

@ -44,6 +44,7 @@ export default {
this.prepareOpenStates(); this.prepareOpenStates();
}, },
mounted() { mounted() {
Mousetrap.bind("esc", this.escapeKey);
Mousetrap.bind("alt+u", this.toggleUserList); Mousetrap.bind("alt+u", this.toggleUserList);
Mousetrap.bind("alt+s", this.toggleSidebar); Mousetrap.bind("alt+s", this.toggleSidebar);
@ -64,6 +65,7 @@ export default {
this.dayChangeTimeout = setTimeout(emitDayChange, this.msUntilNextDay()); this.dayChangeTimeout = setTimeout(emitDayChange, this.msUntilNextDay());
}, },
beforeDestroy() { beforeDestroy() {
Mousetrap.unbind("esc", this.escapeKey);
Mousetrap.unbind("alt+u", this.toggleUserList); Mousetrap.unbind("alt+u", this.toggleUserList);
Mousetrap.unbind("alt+s", this.toggleSidebar); Mousetrap.unbind("alt+s", this.toggleSidebar);
@ -71,6 +73,9 @@ export default {
clearTimeout(this.dayChangeTimeout); clearTimeout(this.dayChangeTimeout);
}, },
methods: { methods: {
escapeKey() {
this.$root.$emit("escapekey");
},
toggleSidebar(e) { toggleSidebar(e) {
// Do not handle this keybind in the chat input because // Do not handle this keybind in the chat input because
// it can be used to type letters with umlauts // it can be used to type letters with umlauts

View File

@ -101,6 +101,8 @@ export default {
}, },
}, },
mounted() { mounted() {
this.$root.$on("escapekey", this.blurInput);
if (this.$store.state.settings.autocomplete) { if (this.$store.state.settings.autocomplete) {
autocompletionRef = autocompletion(this.$refs.input); autocompletionRef = autocompletion(this.$refs.input);
} }
@ -161,6 +163,8 @@ export default {
} }
}, },
destroyed() { destroyed() {
this.$root.$off("escapekey", this.blurInput);
if (autocompletionRef) { if (autocompletionRef) {
autocompletionRef.destroy(); autocompletionRef.destroy();
autocompletionRef = null; autocompletionRef = null;
@ -255,6 +259,9 @@ export default {
openFileUpload() { openFileUpload() {
this.$refs.uploadInput.click(); this.$refs.uploadInput.click();
}, },
blurInput() {
this.$refs.input.blur();
},
}, },
}; };
</script> </script>

View File

@ -38,7 +38,6 @@
</template> </template>
<script> <script>
import Mousetrap from "mousetrap";
import { import {
generateUserContextMenu, generateUserContextMenu,
generateChannelContextMenu, generateChannelContextMenu,
@ -63,15 +62,13 @@ export default {
}; };
}, },
mounted() { mounted() {
Mousetrap.bind("esc", this.close); this.$root.$on("escapekey", this.close);
this.$root.$on("contextmenu:user", this.openUserContextMenu); this.$root.$on("contextmenu:user", this.openUserContextMenu);
this.$root.$on("contextmenu:channel", this.openChannelContextMenu); this.$root.$on("contextmenu:channel", this.openChannelContextMenu);
this.$root.$on("contextmenu:removenetwork", this.openRemoveNetworkContextMenu); this.$root.$on("contextmenu:removenetwork", this.openRemoveNetworkContextMenu);
}, },
destroyed() { destroyed() {
Mousetrap.unbind("esc", this.close); this.$root.$off("escapekey", this.close);
this.$root.$off("contextmenu:user", this.openUserContextMenu); this.$root.$off("contextmenu:user", this.openUserContextMenu);
this.$root.$off("contextmenu:channel", this.openChannelContextMenu); this.$root.$off("contextmenu:channel", this.openChannelContextMenu);
this.$root.$off("contextmenu:removenetwork", this.openRemoveNetworkContextMenu); this.$root.$off("contextmenu:removenetwork", this.openRemoveNetworkContextMenu);

View File

@ -25,8 +25,6 @@
</template> </template>
<script> <script>
import Mousetrap from "mousetrap";
export default { export default {
name: "ImageViewer", name: "ImageViewer",
data() { data() {
@ -68,10 +66,10 @@ export default {
}, },
}, },
mounted() { mounted() {
Mousetrap.bind("esc", this.closeViewer); this.$root.$on("escapekey", this.closeViewer);
}, },
destroyed() { destroyed() {
Mousetrap.unbind("esc", this.closeViewer); this.$root.$off("escapekey", this.closeViewer);
}, },
methods: { methods: {
closeViewer() { closeViewer() {