From a6504e3f47dd3d4cafc186c7f1cbd9c6230d027d Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Wed, 15 Sep 2021 02:02:19 +0200 Subject: [PATCH] Do not stop showing suggestions when entering double colon for separator --- ts/editor/TagEditor.svelte | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index 854a160a1..38e478adc 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -65,19 +65,28 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html return response.tags; } + const colonAtStartOrEnd = /^:?|:?$/g; + function updateSuggestions(): void { const activeTag = tags[active!]; const activeName = activeTag.name; autocompleteDisabled = activeName.length === 0; - suggestionsPromise = autocompleteDisabled - ? noSuggestions - : fetchSuggestions(replaceWithColons(activeTag.name)).then( - (names: string[]): string[] => { - autocompleteDisabled = names.length === 0; - return names.map(replaceWithUnicodeSeparator); - } - ); + + if (autocompleteDisabled) { + suggestionsPromise = noSuggestions; + } else { + const cleanedName = replaceWithColons(activeName).replace( + colonAtStartOrEnd, + "" + ); + suggestionsPromise = fetchSuggestions(cleanedName).then( + (names: string[]): string[] => { + autocompleteDisabled = names.length === 0; + return names.map(replaceWithUnicodeSeparator); + } + ); + } } function onAutocomplete(selected: string): void {