diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index ad111a320..16f442283 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -48,7 +48,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html let activeInput: HTMLInputElement; let autocomplete: any; - let suggestionsPromise: Promise = Promise.resolve([]); + + const noSuggestions = Promise.resolve([]); + let suggestionsPromise: Promise = noSuggestions; async function fetchSuggestions(input: string): Promise { const data = await postRequest( @@ -63,10 +65,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html function updateSuggestions(): void { const activeTag = tags[active!]; + const activeName = activeTag.name; - suggestionsPromise = fetchSuggestions(activeTag.name).then( - (names: string[]): string[] => names.map(replaceWithUnicodeSeparator) - ); + suggestionsPromise = + activeName.length === 0 + ? noSuggestions + : fetchSuggestions(activeTag.name).then((names: string[]): string[] => + names.map(replaceWithUnicodeSeparator) + ); } function onAutocomplete(selected: string): void { diff --git a/ts/editor/WithAutocomplete.svelte b/ts/editor/WithAutocomplete.svelte index 6ca16b3dd..f1dd4345e 100644 --- a/ts/editor/WithAutocomplete.svelte +++ b/ts/editor/WithAutocomplete.svelte @@ -83,10 +83,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html async function chooseSelected() { active = true; dispatch("choose", { chosen: suggestionsItems[selected ?? -1] }); + await tick(); } async function update() { - dropdown = dropdown as Dropdown; dropdown.update(); await tick(); @@ -97,6 +97,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html return selected !== null; } + function disable(): void { + disabled = true; + } + const createAutocomplete = (createDropdown: (element: HTMLElement) => Dropdown) => (element: HTMLElement): any => { @@ -110,8 +114,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html selectPrevious, selectNext, chooseSelected, - hasSelected, update, + hasSelected, + disable, }; return api;