diff --git a/db/migrations/0180__rename_quickSearch_shortcut.sql b/db/migrations/0180__rename_quickSearch_shortcut.sql new file mode 100644 index 000000000..696881c96 --- /dev/null +++ b/db/migrations/0180__rename_quickSearch_shortcut.sql @@ -0,0 +1,2 @@ +UPDATE options SET name = 'keyboardShortcutsQuickSearch' WHERE name = 'keyboardShortcutsSearchNotes'; +UPDATE entity_changes SET entityId = 'keyboardShortcutsQuickSearch' WHERE entityId = 'keyboardShortcutsSearchNotes' AND entityName = 'options'; diff --git a/src/public/app/services/date_notes.js b/src/public/app/services/date_notes.js index 30a734a44..57884811f 100644 --- a/src/public/app/services/date_notes.js +++ b/src/public/app/services/date_notes.js @@ -48,7 +48,7 @@ async function createSearchNote(opts = {}) { const attrsToUpdate = [ opts.ancestorNoteId ? { type: 'relation', name: 'ancestor', value: opts.ancestorNoteId } : undefined, - { type: 'label', name: 'searchString', value: opts.searchStringe } + { type: 'label', name: 'searchString', value: opts.searchString } ].filter(attr => !!attr); if (attrsToUpdate.length > 0) { diff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.js index 1efa0ac22..1475f85e9 100644 --- a/src/public/app/services/frontend_script_api.js +++ b/src/public/app/services/frontend_script_api.js @@ -89,7 +89,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain this.addButtonToToolbar = opts => { const buttonId = "toolbar-button-" + opts.title.replace(/\s/g, "-"); - const button = $(' - + `; -const MAX_DISPLAYED_NOTES = 20; +const MAX_DISPLAYED_NOTES = 15; export default class QuickSearchWidget extends BasicWidget { doRender() { @@ -48,8 +44,9 @@ export default class QuickSearchWidget extends BasicWidget { this.$searchString = this.$widget.find('.search-string'); this.$dropdownMenu = this.$widget.find('.dropdown-menu'); this.$dropdownToggle = this.$widget.find('.search-button'); + this.$dropdownToggle.dropdown(); - this.$widget.find('.input-group-append').on('show.bs.dropdown', () => this.search()); + this.$widget.find('.input-group-append').on('shown.bs.dropdown', () => this.search()); utils.bindElShortcut(this.$searchString, 'return', () => { this.$dropdownToggle.dropdown('show'); @@ -57,21 +54,30 @@ export default class QuickSearchWidget extends BasicWidget { this.$searchString.focus(); }); + utils.bindElShortcut(this.$searchString, 'down', () => { + this.$dropdownMenu.find('.dropdown-item:first').focus(); + }); + return this.$widget; } async search() { + const searchString = this.$searchString.val().trim(); + + if (!searchString) { + this.$dropdownToggle.dropdown("hide"); + return; + } + this.$dropdownMenu.empty(); this.$dropdownMenu.append(' Searching ...'); - const resultNoteIds = await server.get('quick-search/' + encodeURIComponent(this.$searchString.val())); + const resultNoteIds = await server.get('quick-search/' + encodeURIComponent(searchString)); const displayedNoteIds = resultNoteIds.slice(0, Math.min(MAX_DISPLAYED_NOTES, resultNoteIds.length)); this.$dropdownMenu.empty(); - this.$dropdownMenu.append(''); - if (displayedNoteIds.length === 0) { this.$dropdownMenu.append('No results found'); } @@ -79,6 +85,14 @@ export default class QuickSearchWidget extends BasicWidget { for (const note of await treeCache.getNotes(displayedNoteIds)) { const $link = await linkService.createNoteLink(note.noteId, {showNotePath: true}); $link.addClass('dropdown-item'); + $link.attr("tabIndex", "0"); + $link.on('click', () => this.$dropdownToggle.dropdown("hide")); + utils.bindElShortcut($link, 'return', () => { + $link.find('a').trigger({ + type: 'click', + which: 1 // left click + }); + }); this.$dropdownMenu.append($link); } @@ -87,6 +101,23 @@ export default class QuickSearchWidget extends BasicWidget { this.$dropdownMenu.append(`... and ${resultNoteIds.length - MAX_DISPLAYED_NOTES} more results.`); } + const $showInFullButton = $('') + .append($('')); + + this.$dropdownMenu.append($showInFullButton); + + utils.bindElShortcut($showInFullButton, 'return', async () => { + const searchNote = await dateNotesService.createSearchNote({searchString: this.$searchString.val()}); + + await appContext.tabManager.getActiveTabContext().setNote(searchNote.noteId); + }); + + utils.bindElShortcut(this.$dropdownMenu.find('.dropdown-item:first'), 'up', () => this.$searchString.focus()); + this.$dropdownToggle.dropdown('update'); } + + quickSearchEvent() { + this.$searchString.focus(); + } } diff --git a/src/public/app/widgets/standard_top_widget.js b/src/public/app/widgets/standard_top_widget.js index 90055ea7c..873102733 100644 --- a/src/public/app/widgets/standard_top_widget.js +++ b/src/public/app/widgets/standard_top_widget.js @@ -14,7 +14,7 @@ const TPL = ` height: 35px; } - .standard-top-widget button:not(.search-button) { + .standard-top-widget button.noborder { padding: 1px 5px 1px 5px; font-size: 90%; margin-bottom: 2px; @@ -35,35 +35,35 @@ const TPL = `
- - - - - -