Fixed issue with suggestions on multiple terms

This commit is contained in:
Keith Carangelo 2021-09-08 20:45:56 -04:00
parent c6f27b1ade
commit d2019d3a09

View file

@ -48,18 +48,19 @@ function createAwesompleteInstance(element, separator, tags = []) {
// Tags are separated by separator. Ignore leading search flags // Tags are separated by separator. Ignore leading search flags
awesome.filter = (text, input) => { awesome.filter = (text, input) => {
let filterFunc = Awesomplete.FILTER_CONTAINS; let filterFunc = Awesomplete.FILTER_CONTAINS;
const inputFlagged = input.replace(/^[-~+]/, ''); let term = input.match(new RegExp(`[^${separator}]*$`))[0];
if (input !== inputFlagged) { const termFlagged = term.replace(/^[-~+]/, '');
input = inputFlagged; if (term !== termFlagged) {
term = termFlagged;
filterFunc = Awesomplete.FILTER_STARTSWITH; filterFunc = Awesomplete.FILTER_STARTSWITH;
} }
return filterFunc(text, input.match(new RegExp(`[^${separator}]*$`))[0]); return filterFunc(text, term);
}; };
// Insert new selected tag in the input // Insert new selected tag in the input
awesome.replace = (text) => { awesome.replace = (text) => {
const before = awesome.input.value.match(new RegExp(`^.+${separator}+|`))[0]; const before = awesome.input.value.match(new RegExp(`^(.+${separator}+)?[-~+]?|`))[0];
awesome.input.value = `${before}${text}${separator}`; awesome.input.value = `${before}${text}${separator}`;
}; };
// Highlight found items // Highlight found items