Hotfix for duplicates not recognized as changes

This commit is contained in:
Dominik Reh
2022-10-11 22:43:04 +02:00
parent a94be12e86
commit c7258a5839

View File

@@ -110,6 +110,13 @@ const debounce = (func, wait = 300) => {
}
}
// Difference function to fix duplicates not being seen as changes in normal filter
function difference(a, b) {
return [...b.reduce( (acc, v) => acc.set(v, (acc.get(v) || 0) - 1),
a.reduce( (acc, v) => acc.set(v, (acc.get(v) || 0) + 1), new Map() )
)].reduce( (acc, [v, count]) => acc.concat(Array(Math.abs(count)).fill(v)), [] );
}
// Create the result list div and necessary styling
function createResultsDiv() {
let resultsDiv = document.createElement("div");
@@ -186,16 +193,16 @@ function autocomplete(prompt) {
// Match tags with RegEx to get the last edited one
let tags = prompt.match(/[^, ]+/g);
let difference = tags.filter(x => !previousTags.includes(x));
let diff = difference(tags, previousTags)
previousTags = tags;
// Guard for no difference / only whitespace remaining
if (difference == undefined || difference.length == 0) {
if (diff == undefined || diff.length == 0) {
hideResults();
return;
}
let tagword = difference[0]
let tagword = diff[0]
// Guard for empty tagword
if (tagword == undefined || tagword.length == 0) {