Merge pull request #4364 from thelounge/maxleiter/escCloseSearch

Allow escape key to close search bar and search page
This commit is contained in:
Max Leiter 2021-11-18 16:47:21 -08:00 committed by GitHub
commit 6dfd51bb57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -9,6 +9,7 @@
class="input"
placeholder="Search messages…"
@blur="closeSearch"
@keyup.esc="closeSearch"
/>
</div>
<button
@ -113,6 +114,7 @@ export default {
methods: {
closeSearch() {
if (!this.onSearchPage) {
this.searchInput = "";
this.searchOpened = false;
}
},

View file

@ -93,6 +93,7 @@
<script>
import socket from "../../js/socket";
import eventbus from "../../js/eventbus";
import SidebarToggle from "../SidebarToggle.vue";
import Message from "../Message.vue";
@ -171,11 +172,16 @@ export default {
mounted() {
this.setActiveChannel();
this.doSearch();
eventbus.on("escapekey", this.closeSearch);
this.$root.$on("re-search", this.doSearch); // Enable MessageSearchForm to search for the same query again
},
beforeDestroy() {
this.$root.$off("re-search");
},
destroyed() {
eventbus.off("escapekey", this.closeSearch);
},
methods: {
setActiveChannel() {
this.$store.commit("activeChannel", this.chan);