diff --git a/packages/text-editor/src/components/MentionPopup.svelte b/packages/text-editor/src/components/MentionPopup.svelte index d285afc93f..15f726a92d 100644 --- a/packages/text-editor/src/components/MentionPopup.svelte +++ b/packages/text-editor/src/components/MentionPopup.svelte @@ -38,10 +38,15 @@ const client = getClient() - client.findAll(presentation.class.ObjectSearchCategory, { context: 'mention' }).then(async (results) => { - categories = results - updateItems(query) - }) + client + .findAll(presentation.class.ObjectSearchCategory, { context: 'mention' }) + .then(async (results) => { + categories = results + await updateItems(query) + }) + .catch((e) => { + console.error(e) + }) const dispatch = createEventDispatcher() @@ -76,8 +81,8 @@ if (key.key === 'Enter' || key.key === 'Tab') { key.preventDefault() key.stopPropagation() - const searchItem = items[selection] - if (searchItem) { + if (selection < items.length) { + const searchItem = items[selection] dispatchItem(searchItem.item) return true } else { @@ -87,8 +92,6 @@ return false } - export function done () {} - function packSearchResultsForListView (sections: SearchSection[]): SearchItem[] { let results: SearchItem[] = [] for (const section of sections) { @@ -161,10 +164,11 @@ const sections = await doFulltextSearch(classesToSearch, query) items = packSearchResultsForListView(sections) } - $: updateItems(query) + $: void updateItems(query) {#if (items.length === 0 && query !== '') || items.length > 0} +