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
awesome.filter = (text, input) => {
let filterFunc = Awesomplete.FILTER_CONTAINS;
const inputFlagged = input.replace(/^[-~+]/, '');
if (input !== inputFlagged) {
input = inputFlagged;
let term = input.match(new RegExp(`[^${separator}]*$`))[0];
const termFlagged = term.replace(/^[-~+]/, '');
if (term !== termFlagged) {
term = termFlagged;
filterFunc = Awesomplete.FILTER_STARTSWITH;
}
return filterFunc(text, input.match(new RegExp(`[^${separator}]*$`))[0]);
return filterFunc(text, term);
};
// Insert new selected tag in the input
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}`;
};
// Highlight found items