From: Adam Dullage Date: Sun, 7 Aug 2022 18:19:04 +0000 (+0100) Subject: Search UX improvements X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=3afdfe6511e080fa4018710e2daba2b640dd01be;p=flatnotes.git Search UX improvements --- diff --git a/flatnotes/src/components/App.js b/flatnotes/src/components/App.js index 54442b9..28f1104 100644 --- a/flatnotes/src/components/App.js +++ b/flatnotes/src/components/App.js @@ -35,9 +35,14 @@ export default { let path = window.location.pathname.split("/"); let basePath = path[1]; + this.$bvModal.hide("search-modal"); + // Home Page if (basePath == "") { this.currentView = this.views.home; + this.$nextTick(function() { + this.focusSearchInput(); + }); } // Search @@ -375,7 +380,29 @@ export default { }); }, + focusSearchInput: function() { + document.getElementById("search-input").focus(); + }, + + openSearch: function() { + if (this.currentView == this.views.home) { + this.focusSearchInput(); + EventBus.$emit("highlight-search-input"); + } else if (this.currentView != this.views.login) { + this.$bvModal.show("search-modal"); + } + }, + keyboardShortcuts: function(e) { + // If the user is focused on a text input or is editing a note, ignore. + if ( + !["e", "/"].includes(e.key) || + document.activeElement.type == "text" || + (this.currentView == this.views.note && this.editMode == true) + ) { + return; + } + // 'e' to Edit if ( e.key == "e" && @@ -386,6 +413,12 @@ export default { this.toggleEditMode(); } + // '/' to Search + if (e.key == "/") { + e.preventDefault(); + this.openSearch(); + } + // 'CTRL + s' to Save // else if ( // e.key == "s" && @@ -424,6 +457,14 @@ export default { }, mounted: function() { + let parent = this; + window.addEventListener("popstate", this.route); + + this.$root.$on("bv::modal::shown", function(_, modalId) { + if (modalId == "search-modal") { + parent.focusSearchInput(); + } + }); }, }; diff --git a/flatnotes/src/components/App.vue b/flatnotes/src/components/App.vue index 7eeb8b7..015d77d 100644 --- a/flatnotes/src/components/App.vue +++ b/flatnotes/src/components/App.vue @@ -1,5 +1,10 @@ @@ -43,26 +55,18 @@ diff --git a/flatnotes/src/components/SearchInput.vue b/flatnotes/src/components/SearchInput.vue index 06d0e90..9e32967 100644 --- a/flatnotes/src/components/SearchInput.vue +++ b/flatnotes/src/components/SearchInput.vue @@ -2,11 +2,12 @@