From db79f231a0d731962a848430b5e48015a344c83c Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Wed, 13 Nov 2024 17:13:07 +0800 Subject: [PATCH 1/5] Triggers full text search when Ctrl + Enter is pressed in note_autocomplete --- src/public/app/services/note_autocomplete.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/public/app/services/note_autocomplete.js b/src/public/app/services/note_autocomplete.js index dbee214b7..5932e6177 100644 --- a/src/public/app/services/note_autocomplete.js +++ b/src/public/app/services/note_autocomplete.js @@ -132,6 +132,19 @@ function initNoteAutocomplete($el, options) { return false; }); + // Triggers full text search when Ctrl + Enter is pressed. + $el.on('keydown', (event) => { + if (event.key === 'Enter') { + if (event.ctrlKey) { + // Prevent Ctrl + Enter from triggering autoComplete. + event.preventDefault(); + event.stopImmediatePropagation(); + const searchString = $el.val(); + appContext.triggerCommand('searchNotes', { searchString }); + } + } + }); + let autocompleteOptions = {}; if (options.container) { autocompleteOptions.dropdownMenuContainer = options.container; From 4e100716497cccfaa76c3bbe8ddcaceb0c42775a Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Sun, 17 Nov 2024 12:14:44 +0800 Subject: [PATCH 2/5] Triggers full text search when Ctrl + Enter is pressed in autocomplete --- src/public/app/widgets/dialogs/jump_to_note.js | 10 ++++++++++ src/public/app/widgets/type_widgets/empty.js | 12 ++++++++++++ src/public/translations/en/translation.json | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/public/app/widgets/dialogs/jump_to_note.js b/src/public/app/widgets/dialogs/jump_to_note.js index 5324b4588..627975659 100644 --- a/src/public/app/widgets/dialogs/jump_to_note.js +++ b/src/public/app/widgets/dialogs/jump_to_note.js @@ -38,6 +38,16 @@ export default class JumpToNoteDialog extends BasicWidget { this.modal = bootstrap.Modal.getOrCreateInstance(this.$widget); this.$autoComplete = this.$widget.find(".jump-to-note-autocomplete"); + this.$autoComplete.on('keydown', (event) => { + if (event.ctrlKey && event.key === 'Enter') { + // Prevent Ctrl + Enter from triggering autoComplete. + event.stopImmediatePropagation(); + event.preventDefault(); + const searchString = this.$autoComplete.val(); + appContext.triggerCommand('searchNotes', { searchString }); + } + + }); this.$results = this.$widget.find(".jump-to-note-results"); this.$showInFullTextButton = this.$widget.find(".show-in-full-text-button"); this.$showInFullTextButton.on('click', e => this.showInFullText(e)); diff --git a/src/public/app/widgets/type_widgets/empty.js b/src/public/app/widgets/type_widgets/empty.js index 38418d398..e297678a5 100644 --- a/src/public/app/widgets/type_widgets/empty.js +++ b/src/public/app/widgets/type_widgets/empty.js @@ -65,6 +65,18 @@ export default class EmptyTypeWidget extends TypeWidget { this.$widget = $(TPL); this.$autoComplete = this.$widget.find(".note-autocomplete"); + + this.$autoComplete.on('keydown', (event) => { + if (event.ctrlKey && event.key === 'Enter') { + // Prevent Ctrl + Enter from triggering autoComplete. + event.stopImmediatePropagation(); + event.preventDefault(); + const searchString = this.$autoComplete.val(); + appContext.triggerCommand('searchNotes', { searchString }); + } + + }); + this.$results = this.$widget.find(".note-detail-empty-results"); noteAutocompleteService.initNoteAutocomplete(this.$autoComplete, { diff --git a/src/public/translations/en/translation.json b/src/public/translations/en/translation.json index 66a135935..edefbf5dd 100644 --- a/src/public/translations/en/translation.json +++ b/src/public/translations/en/translation.json @@ -922,7 +922,7 @@ }, "empty": { "open_note_instruction": "Open a note by typing the note's title into the input below or choose a note in the tree.", - "search_placeholder": "search for a note by its name", + "search_placeholder": "search for a note by its name, Ctrl+Enter for full-text search.", "enter_workspace": "Enter workspace {{title}}" }, "file": { From e091ef64dd15753b946e46feab9e6ab52fb2613b Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Sun, 17 Nov 2024 12:17:11 +0800 Subject: [PATCH 3/5] Triggers full text search when Ctrl + Enter is pressed --- src/public/app/services/note_autocomplete.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/public/app/services/note_autocomplete.js b/src/public/app/services/note_autocomplete.js index 5932e6177..52f0c2bc3 100644 --- a/src/public/app/services/note_autocomplete.js +++ b/src/public/app/services/note_autocomplete.js @@ -131,19 +131,6 @@ function initNoteAutocomplete($el, options) { // this is important because otherwise input will lose focus immediately and not show the results return false; }); - - // Triggers full text search when Ctrl + Enter is pressed. - $el.on('keydown', (event) => { - if (event.key === 'Enter') { - if (event.ctrlKey) { - // Prevent Ctrl + Enter from triggering autoComplete. - event.preventDefault(); - event.stopImmediatePropagation(); - const searchString = $el.val(); - appContext.triggerCommand('searchNotes', { searchString }); - } - } - }); let autocompleteOptions = {}; if (options.container) { From 002839176ebab68a4915e1549a2c46e796f194ef Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Sun, 17 Nov 2024 12:18:05 +0800 Subject: [PATCH 4/5] Triggers full text search when Ctrl + Enter is pressed --- src/public/app/services/note_autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/public/app/services/note_autocomplete.js b/src/public/app/services/note_autocomplete.js index 52f0c2bc3..dbee214b7 100644 --- a/src/public/app/services/note_autocomplete.js +++ b/src/public/app/services/note_autocomplete.js @@ -131,7 +131,7 @@ function initNoteAutocomplete($el, options) { // this is important because otherwise input will lose focus immediately and not show the results return false; }); - + let autocompleteOptions = {}; if (options.container) { autocompleteOptions.dropdownMenuContainer = options.container; From c51adbc449d5b29b1a9c61b1af5560e7908d16c0 Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Wed, 20 Nov 2024 14:22:39 +0800 Subject: [PATCH 5/5] Add full text search in autocomplete --- src/public/app/services/note_autocomplete.js | 27 +++++++++++++++++++ .../app/widgets/dialogs/jump_to_note.js | 11 +------- src/public/app/widgets/type_widgets/empty.js | 13 +-------- src/public/translations/en/translation.json | 2 +- 4 files changed, 30 insertions(+), 23 deletions(-) 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 627975659..ff4c4939b 100644 --- a/src/public/app/widgets/dialogs/jump_to_note.js +++ b/src/public/app/widgets/dialogs/jump_to_note.js @@ -38,16 +38,6 @@ export default class JumpToNoteDialog extends BasicWidget { this.modal = bootstrap.Modal.getOrCreateInstance(this.$widget); this.$autoComplete = this.$widget.find(".jump-to-note-autocomplete"); - this.$autoComplete.on('keydown', (event) => { - if (event.ctrlKey && event.key === 'Enter') { - // Prevent Ctrl + Enter from triggering autoComplete. - event.stopImmediatePropagation(); - event.preventDefault(); - const searchString = this.$autoComplete.val(); - appContext.triggerCommand('searchNotes', { searchString }); - } - - }); this.$results = this.$widget.find(".jump-to-note-results"); this.$showInFullTextButton = this.$widget.find(".show-in-full-text-button"); this.$showInFullTextButton.on('click', e => this.showInFullText(e)); @@ -68,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 e297678a5..24d60b4fb 100644 --- a/src/public/app/widgets/type_widgets/empty.js +++ b/src/public/app/widgets/type_widgets/empty.js @@ -65,23 +65,12 @@ export default class EmptyTypeWidget extends TypeWidget { this.$widget = $(TPL); this.$autoComplete = this.$widget.find(".note-autocomplete"); - - this.$autoComplete.on('keydown', (event) => { - if (event.ctrlKey && event.key === 'Enter') { - // Prevent Ctrl + Enter from triggering autoComplete. - event.stopImmediatePropagation(); - event.preventDefault(); - const searchString = this.$autoComplete.val(); - appContext.triggerCommand('searchNotes', { searchString }); - } - - }); - this.$results = this.$widget.find(".note-detail-empty-results"); noteAutocompleteService.initNoteAutocomplete(this.$autoComplete, { hideGoToSelectedNoteButton: true, allowCreatingNotes: true, + allowSearchNotes: true, container: this.$results }) .on('autocomplete:noteselected', function(event, suggestion, dataset) { diff --git a/src/public/translations/en/translation.json b/src/public/translations/en/translation.json index 388e37d6a..9847b0e24 100644 --- a/src/public/translations/en/translation.json +++ b/src/public/translations/en/translation.json @@ -922,7 +922,7 @@ }, "empty": { "open_note_instruction": "Open a note by typing the note's title into the input below or choose a note in the tree.", - "search_placeholder": "search for a note by its name, Ctrl+Enter for full-text search.", + "search_placeholder": "search for a note by its name", "enter_workspace": "Enter workspace {{title}}" }, "file": {