Fix suggestions not showing when typing space in a TagInput

This commit is contained in:
Henrik Giesel 2021-09-15 22:54:34 +02:00
parent b502ceedca
commit 9f56d51811
2 changed files with 8 additions and 6 deletions

View file

@ -65,7 +65,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
return response.tags; return response.tags;
} }
const colonAtStartOrEnd = /^:?|:?$/g; const withoutSingleColonAtStartOrEnd = /^:?([^:].*?[^:]):?$/;
function updateSuggestions(): void { function updateSuggestions(): void {
const activeTag = tags[active!]; const activeTag = tags[active!];
@ -76,11 +76,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
if (autocompleteDisabled) { if (autocompleteDisabled) {
suggestionsPromise = noSuggestions; suggestionsPromise = noSuggestions;
} else { } else {
const cleanedName = replaceWithColons(activeName).replace( const withColons = replaceWithColons(activeName);
colonAtStartOrEnd, const withoutSingleColons = withoutSingleColonAtStartOrEnd.test(withColons)
"" ? withColons.replace(withoutSingleColonAtStartOrEnd, "$1")
); : withColons;
suggestionsPromise = fetchSuggestions(cleanedName).then(
suggestionsPromise = fetchSuggestions(withoutSingleColons).then(
(names: string[]): string[] => { (names: string[]): string[] => {
autocompleteDisabled = names.length === 0; autocompleteDisabled = names.length === 0;
return names.map(replaceWithUnicodeSeparator); return names.map(replaceWithUnicodeSeparator);

View file

@ -132,6 +132,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
await tick(); await tick();
setPosition(positionStart); setPosition(positionStart);
dispatch("taginput");
return; return;
} else if (after.startsWith(":")) { } else if (after.startsWith(":")) {
event.preventDefault(); event.preventDefault();