diff --git a/src/public/app/dialogs/add_link.js b/src/public/app/dialogs/add_link.js index de5fa2d07..d56538501 100644 --- a/src/public/app/dialogs/add_link.js +++ b/src/public/app/dialogs/add_link.js @@ -42,7 +42,9 @@ export async function showDialog(widget) { noteAutocompleteService.initNoteAutocomplete($autoComplete); - $autoComplete.on('autocomplete:selected', function(event, suggestion, dataset) { + $autoComplete.on('autocomplete:noteselected', function(event, suggestion, dataset) { + console.log("SELECTED", suggestion); + if (!suggestion.notePath) { return false; } diff --git a/src/public/app/services/note_autocomplete.js b/src/public/app/services/note_autocomplete.js index 3f736c5b6..d44a4ee22 100644 --- a/src/public/app/services/note_autocomplete.js +++ b/src/public/app/services/note_autocomplete.js @@ -1,16 +1,31 @@ import server from "./server.js"; import appContext from "./app_context.js"; import utils from './utils.js'; +import noteCreateService from './note_create.js'; +import treeService from './tree.js'; // this key needs to have this value so it's hit by the tooltip const SELECTED_NOTE_PATH_KEY = "data-note-path"; async function autocompleteSource(term, cb) { - const result = await server.get('autocomplete' - + '?query=' + encodeURIComponent(term) - + '&activeNoteId=' + appContext.tabManager.getActiveTabNoteId()); + const activeNoteId = appContext.tabManager.getActiveTabNoteId(); - cb(result); + let results = await server.get('autocomplete' + + '?query=' + encodeURIComponent(term) + + '&activeNoteId=' + activeNoteId); + + if (term.trim().length >= 1) { + results = [ + { + action: 'create', + noteTitle: term, + parentNoteId: activeNoteId, + highlightedNotePathTitle: `Create and link child note "${term}"` + } + ].concat(results); + } + + cb(results); } function clearText($el) { @@ -86,19 +101,30 @@ function initNoteAutocomplete($el, options) { source: autocompleteSource, displayKey: 'notePathTitle', templates: { - suggestion: function(suggestion) { - return suggestion.highlightedNotePathTitle; - } + suggestion: suggestion => suggestion.highlightedNotePathTitle }, // we can't cache identical searches because notes can be created / renamed, new recent notes can be added cache: false } ]); - $el.on('autocomplete:selected', (event, suggestion) => { + $el.on('autocomplete:selected', async (event, suggestion) => { + if (suggestion.action === 'create') { + const {note} = await noteCreateService.createNote(suggestion.parentNoteId, { + title: suggestion.noteTitle, + activate: false + }); + + suggestion.notePath = treeService.getSomeNotePath(note); + } + $el.setSelectedNotePath(suggestion.notePath); $el.autocomplete("val", suggestion.noteTitle); + + $el.autocomplete("close"); + + $el.trigger('autocomplete:noteselected', [event, suggestion]); }); $el.on('autocomplete:closed', () => { diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css index 739e297ab..73592d2f4 100644 --- a/src/public/stylesheets/style.css +++ b/src/public/stylesheets/style.css @@ -666,10 +666,14 @@ a.external:not(.no-arrow):after, a[href^="http://"]:not(.no-arrow):after, a[href } .ck-mentions .ck-button { - font-size: var(--main-font-size) !important; + font-size: var(--detail-font-size) !important; padding: 5px; } +.ck-mentions .ck-button b { + font-size: var(--detail-font-size) !important; +} + .ck-mentions .ck-button.ck-on { background-color: var(--active-item-background-color) !important; color: var(--active-item-text-color) !important;