diff --git a/src/public/app/services/note_autocomplete.js b/src/public/app/services/note_autocomplete.js index dbee214b7..5dbb25c03 100644 --- a/src/public/app/services/note_autocomplete.js +++ b/src/public/app/services/note_autocomplete.js @@ -45,6 +45,16 @@ async function autocompleteSource(term, cb, options = {}) { ].concat(results); } + if (term.trim().length >= 1 && options.allowSearchNotes) { + results = results.concat([ + { + action: 'search-notes', + noteTitle: term, + highlightedNotePathTitle: `Search for "${utils.escapeHtml(term)}" Ctrl+Enter` + } + ]); + } + if (term.match(/^[a-z]+:\/\/.+/i) && options.allowExternalLinks) { results = [ { @@ -138,6 +148,17 @@ function initNoteAutocomplete($el, options) { autocompleteOptions.debug = true; // don't close on blur } + if (options.allowSearchNotes) { + $el.on('keydown', (event) => { + if (event.ctrlKey && event.key === 'Enter') { + // Prevent Ctrl + Enter from triggering autoComplete. + event.stopImmediatePropagation(); + event.preventDefault(); + $el.trigger('autocomplete:selected', { action: 'search-notes', noteTitle: $el.autocomplete("val")}); + } + }); + } + $el.autocomplete({ ...autocompleteOptions, appendTo: document.querySelector('body'), @@ -192,6 +213,12 @@ function initNoteAutocomplete($el, options) { suggestion.notePath = note.getBestNotePathString(hoistedNoteId); } + if (suggestion.action === 'search-notes') { + const searchString = suggestion.noteTitle; + appContext.triggerCommand('searchNotes', { searchString }); + return; + } + $el.setSelectedNotePath(suggestion.notePath); $el.setSelectedExternalLink(null); diff --git a/src/public/app/widgets/dialogs/jump_to_note.js b/src/public/app/widgets/dialogs/jump_to_note.js index 5324b4588..ff4c4939b 100644 --- a/src/public/app/widgets/dialogs/jump_to_note.js +++ b/src/public/app/widgets/dialogs/jump_to_note.js @@ -58,6 +58,7 @@ export default class JumpToNoteDialog extends BasicWidget { noteAutocompleteService.initNoteAutocomplete(this.$autoComplete, { allowCreatingNotes: true, hideGoToSelectedNoteButton: true, + allowSearchNotes: true, container: this.$results }) // clear any event listener added in previous invocation of this function diff --git a/src/public/app/widgets/type_widgets/empty.js b/src/public/app/widgets/type_widgets/empty.js index 38418d398..24d60b4fb 100644 --- a/src/public/app/widgets/type_widgets/empty.js +++ b/src/public/app/widgets/type_widgets/empty.js @@ -70,6 +70,7 @@ export default class EmptyTypeWidget extends TypeWidget { noteAutocompleteService.initNoteAutocomplete(this.$autoComplete, { hideGoToSelectedNoteButton: true, allowCreatingNotes: true, + allowSearchNotes: true, container: this.$results }) .on('autocomplete:noteselected', function(event, suggestion, dataset) {