mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-18 15:08:00 +01:00
Support suggesting tags when -
syntax used in tag editor
This commit is contained in:
parent
1853c8984f
commit
9a0ae3971b
1 changed files with 11 additions and 3 deletions
|
@ -44,6 +44,10 @@ function applySelectedValue(selection: string) {
|
|||
if (!inputField) return;
|
||||
|
||||
if (!isSearchField(inputField)) {
|
||||
if (originalTerm?.startsWith('-')) {
|
||||
selection = `-${selection}`;
|
||||
}
|
||||
|
||||
inputField.value = selection;
|
||||
return;
|
||||
}
|
||||
|
@ -121,6 +125,10 @@ function toggleSearchAutocomplete() {
|
|||
}
|
||||
}
|
||||
|
||||
function trimPrefixes(targetTerm: string): string {
|
||||
return targetTerm.trim().replace(/^-/, '');
|
||||
}
|
||||
|
||||
function listenAutocomplete() {
|
||||
let serverSideSuggestionsTimeout: number | undefined;
|
||||
|
||||
|
@ -162,7 +170,7 @@ function listenAutocomplete() {
|
|||
}
|
||||
|
||||
const suggestions = localAc
|
||||
.matchPrefix(originalTerm)
|
||||
.matchPrefix(trimPrefixes(originalTerm))
|
||||
.topK(suggestionsCount)
|
||||
.map(({ name, imageCount }) => ({ label: `${name} (${imageCount})`, value: name }));
|
||||
|
||||
|
@ -181,13 +189,13 @@ function listenAutocomplete() {
|
|||
inputField = targetedInput;
|
||||
originalTerm = inputField.value;
|
||||
|
||||
const fetchedTerm = inputField.value;
|
||||
const fetchedTerm = trimPrefixes(inputField.value);
|
||||
|
||||
if (minTermLength && fetchedTerm.length < parseInt(minTermLength, 10)) return;
|
||||
|
||||
fetchSuggestions(endpointUrl, fetchedTerm).then(suggestions => {
|
||||
// inputField could get overwritten while the suggestions are being fetched - use previously targeted input
|
||||
if (fetchedTerm === targetedInput.value) {
|
||||
if (fetchedTerm === trimPrefixes(targetedInput.value)) {
|
||||
popup.renderSuggestions(suggestions).showForField(targetedInput);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue