fix indents
This commit is contained in:
+72
-72
@@ -103,85 +103,85 @@ function searchCompletionCandidates(textareaElement) {
|
||||
|
||||
const sources = getEnabledTagSourceInPriorityOrder();
|
||||
for (const source of sources) {
|
||||
if (autoCompleteData[source].use_fuse && autoCompleteData[source].fuse) {
|
||||
const searchResults = autoCompleteData[source].fuse.search(partialTag, {
|
||||
limit: settingValues.maxSuggestions,
|
||||
suggest: false,
|
||||
cache: true,
|
||||
});
|
||||
if (settingValues._logprocessingTime) {
|
||||
const endTime = performance.now();
|
||||
const duration = endTime - startTime;
|
||||
console.debug(`[Autocomplete-Plus] Fast Search for "${partialTag}" in ${source} took ${duration.toFixed(2)}ms. Found ${searchResults.length} candidates.`);
|
||||
}
|
||||
let result = [];
|
||||
searchResults.sort((a, b) => {
|
||||
if (matchWord(autoCompleteData[source].sortedTags[b].tag, queryVariations).matched) {
|
||||
return 999999999999;
|
||||
}
|
||||
if (matchWord(autoCompleteData[source].sortedTags[a].tag, queryVariations).matched) {
|
||||
return -999999999999;
|
||||
}
|
||||
return autoCompleteData[source].sortedTags[b].count - autoCompleteData[source].sortedTags[a].count;
|
||||
}).forEach(seachResult => {
|
||||
result.push(autoCompleteData[source].sortedTags[seachResult]);
|
||||
});
|
||||
return result;
|
||||
} else {
|
||||
// Search in sortedTags (already sorted by count)
|
||||
for (const tagData of autoCompleteData[source].sortedTags) {
|
||||
let matched = false;
|
||||
let isExactMatch = false;
|
||||
let matchedAlias = null;
|
||||
if (autoCompleteData[source].use_fuse && autoCompleteData[source].fuse) {
|
||||
const searchResults = autoCompleteData[source].fuse.search(partialTag, {
|
||||
limit: settingValues.maxSuggestions,
|
||||
suggest: false,
|
||||
cache: true,
|
||||
});
|
||||
if (settingValues._logprocessingTime) {
|
||||
const endTime = performance.now();
|
||||
const duration = endTime - startTime;
|
||||
console.debug(`[Autocomplete-Plus] Fast Search for "${partialTag}" in ${source} took ${duration.toFixed(2)}ms. Found ${searchResults.length} candidates.`);
|
||||
}
|
||||
let result = [];
|
||||
searchResults.sort((a, b) => {
|
||||
if (matchWord(autoCompleteData[source].sortedTags[b].tag, queryVariations).matched) {
|
||||
return 999999999999;
|
||||
}
|
||||
if (matchWord(autoCompleteData[source].sortedTags[a].tag, queryVariations).matched) {
|
||||
return -999999999999;
|
||||
}
|
||||
return autoCompleteData[source].sortedTags[b].count - autoCompleteData[source].sortedTags[a].count;
|
||||
}).forEach(seachResult => {
|
||||
result.push(autoCompleteData[source].sortedTags[seachResult]);
|
||||
});
|
||||
return result;
|
||||
} else {
|
||||
// Search in sortedTags (already sorted by count)
|
||||
for (const tagData of autoCompleteData[source].sortedTags) {
|
||||
let matched = false;
|
||||
let isExactMatch = false;
|
||||
let matchedAlias = null;
|
||||
|
||||
// Check primary tag against all variations for exact/partial match
|
||||
const tagMatch = matchWord(tagData.tag, queryVariations);
|
||||
matched = tagMatch.matched;
|
||||
isExactMatch = tagMatch.isExactMatch;
|
||||
// Check primary tag against all variations for exact/partial match
|
||||
const tagMatch = matchWord(tagData.tag, queryVariations);
|
||||
matched = tagMatch.matched;
|
||||
isExactMatch = tagMatch.isExactMatch;
|
||||
|
||||
// If primary tag didn't match, check aliases against all variations
|
||||
if (!matched && tagData.alias && Array.isArray(tagData.alias) && tagData.alias.length > 0) {
|
||||
for (const alias of tagData.alias) {
|
||||
const lowerAlias = alias.toLowerCase();
|
||||
const aliasMatch = matchWord(lowerAlias, queryVariations);
|
||||
if (aliasMatch.matched) {
|
||||
matched = true;
|
||||
isExactMatch = aliasMatch.isExactMatch;
|
||||
matchedAlias = alias;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If primary tag didn't match, check aliases against all variations
|
||||
if (!matched && tagData.alias && Array.isArray(tagData.alias) && tagData.alias.length > 0) {
|
||||
for (const alias of tagData.alias) {
|
||||
const lowerAlias = alias.toLowerCase();
|
||||
const aliasMatch = matchWord(lowerAlias, queryVariations);
|
||||
if (aliasMatch.matched) {
|
||||
matched = true;
|
||||
isExactMatch = aliasMatch.isExactMatch;
|
||||
matchedAlias = alias;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const tagSetKey = tagData.tag;
|
||||
const tagSetKey = tagData.tag;
|
||||
|
||||
// Add candidate if matched and not already added
|
||||
if (matched && !addedTags.has(tagSetKey)) {
|
||||
// Add to exact matches or partial matches based on match type
|
||||
if (isExactMatch) {
|
||||
exactMatches.push(tagData);
|
||||
} else {
|
||||
partialMatches.push(tagData);
|
||||
}
|
||||
// Add candidate if matched and not already added
|
||||
if (matched && !addedTags.has(tagSetKey)) {
|
||||
// Add to exact matches or partial matches based on match type
|
||||
if (isExactMatch) {
|
||||
exactMatches.push(tagData);
|
||||
} else {
|
||||
partialMatches.push(tagData);
|
||||
}
|
||||
|
||||
addedTags.add(tagSetKey);
|
||||
addedTags.add(tagSetKey);
|
||||
|
||||
// Check if we've reached the maximum suggestions limit combining both arrays
|
||||
if (exactMatches.length + partialMatches.length >= settingValues.maxSuggestions) {
|
||||
// Return the combined results, prioritizing exact matches
|
||||
const result = [...exactMatches, ...partialMatches].slice(0, settingValues.maxSuggestions);
|
||||
// Check if we've reached the maximum suggestions limit combining both arrays
|
||||
if (exactMatches.length + partialMatches.length >= settingValues.maxSuggestions) {
|
||||
// Return the combined results, prioritizing exact matches
|
||||
const result = [...exactMatches, ...partialMatches].slice(0, settingValues.maxSuggestions);
|
||||
|
||||
if (settingValues._logprocessingTime) {
|
||||
const endTime = performance.now();
|
||||
const duration = endTime - startTime;
|
||||
console.debug(`[Autocomplete-Plus] Search for "${partialTag}" took ${duration.toFixed(2)}ms. Found ${result.length} candidates (max reached).`);
|
||||
}
|
||||
if (settingValues._logprocessingTime) {
|
||||
const endTime = performance.now();
|
||||
const duration = endTime - startTime;
|
||||
console.debug(`[Autocomplete-Plus] Search for "${partialTag}" took ${duration.toFixed(2)}ms. Found ${result.length} candidates (max reached).`);
|
||||
}
|
||||
|
||||
return result; // Early exit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result; // Early exit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Combine results, with exact matches first
|
||||
@@ -208,7 +208,7 @@ function getCurrentPartialTag(inputElement) {
|
||||
// Find the last newline or comma before the cursor
|
||||
const lastNewLine = text.lastIndexOf('\n', cursorPos - 1);
|
||||
const lastComma = text.lastIndexOf(',', cursorPos - 1);
|
||||
const lastPeriod = text.lastIndexOf('.', cursorPos - 1);
|
||||
const lastPeriod = text.lastIndexOf('.', cursorPos - 1);
|
||||
|
||||
// Get the position of the last separator (newline or comma) before cursor
|
||||
const lastSeparator = Math.max(lastNewLine, lastComma, lastPeriod);
|
||||
|
||||
+35
-35
@@ -64,11 +64,11 @@ export class TagData {
|
||||
|
||||
class AutocompleteData {
|
||||
constructor() {
|
||||
/** @type {Index} */
|
||||
this.fuse = null;
|
||||
/** @type {Index} */
|
||||
this.fuse = null;
|
||||
|
||||
/** @type {boolean} */
|
||||
this.use_fuse = false;
|
||||
/** @type {boolean} */
|
||||
this.use_fuse = false;
|
||||
|
||||
/** @type {TagData[]} */
|
||||
this.sortedTags = [];
|
||||
@@ -189,39 +189,39 @@ async function loadTags(csvUrl, siteName) {
|
||||
}
|
||||
});
|
||||
|
||||
autoCompleteData[siteName].fuse = new Index({
|
||||
tokenize: "forward",
|
||||
});
|
||||
autoCompleteData[siteName].fuse = new Index({
|
||||
tokenize: "forward",
|
||||
});
|
||||
|
||||
let startIdx = 0;
|
||||
const startTime = performance.now();
|
||||
function processChunkTasks() {
|
||||
const chunkSize = 1000;
|
||||
const end = Math.min(startIdx + chunkSize, autoCompleteData[siteName].sortedTags.length);
|
||||
for (; startIdx < end; startIdx++) {
|
||||
const tagData = autoCompleteData[siteName].sortedTags[startIdx];
|
||||
let allTags = [];
|
||||
allTags.push(tagData.tag);
|
||||
if (tagData.alias && Array.isArray(tagData.alias)) {
|
||||
tagData.alias.forEach(alias => {
|
||||
allTags.push(alias);
|
||||
});
|
||||
}
|
||||
allTags = [...new Set(allTags)];
|
||||
autoCompleteData[siteName].fuse.add(startIdx, allTags.join(','));
|
||||
}
|
||||
let startIdx = 0;
|
||||
const startTime = performance.now();
|
||||
function processChunkTasks() {
|
||||
const chunkSize = 1000;
|
||||
const end = Math.min(startIdx + chunkSize, autoCompleteData[siteName].sortedTags.length);
|
||||
for (; startIdx < end; startIdx++) {
|
||||
const tagData = autoCompleteData[siteName].sortedTags[startIdx];
|
||||
let allTags = [];
|
||||
allTags.push(tagData.tag);
|
||||
if (tagData.alias && Array.isArray(tagData.alias)) {
|
||||
tagData.alias.forEach(alias => {
|
||||
allTags.push(alias);
|
||||
});
|
||||
}
|
||||
allTags = [...new Set(allTags)];
|
||||
autoCompleteData[siteName].fuse.add(startIdx, allTags.join(','));
|
||||
}
|
||||
|
||||
if (startIdx < autoCompleteData[siteName].sortedTags.length) {
|
||||
setTimeout(processChunkTasks, 0);
|
||||
// console.log(`[Autocomplete-Plus] Current porcess: ${startIdx}`);
|
||||
} else {
|
||||
const endTime = performance.now();
|
||||
const duration = endTime - startTime;
|
||||
autoCompleteData[siteName].use_fuse = true;
|
||||
console.debug(`[Autocomplete-Plus] Building ${autoCompleteData[siteName].sortedTags.length} index for ${siteName} took ${duration.toFixed(2)}ms.`);
|
||||
}
|
||||
}
|
||||
processChunkTasks();
|
||||
if (startIdx < autoCompleteData[siteName].sortedTags.length) {
|
||||
setTimeout(processChunkTasks, 0);
|
||||
// console.log(`[Autocomplete-Plus] Current porcess: ${startIdx}`);
|
||||
} else {
|
||||
const endTime = performance.now();
|
||||
const duration = endTime - startTime;
|
||||
autoCompleteData[siteName].use_fuse = true;
|
||||
console.debug(`[Autocomplete-Plus] Building ${autoCompleteData[siteName].sortedTags.length} index for ${siteName} took ${duration.toFixed(2)}ms.`);
|
||||
}
|
||||
}
|
||||
processChunkTasks();
|
||||
} catch (error) {
|
||||
console.error(`[Autocomplete-Plus] Failed to fetch or process tags from ${csvUrl}:`, error);
|
||||
}
|
||||
|
||||
+1
-1
@@ -21,4 +21,4 @@ export const settingValues = {
|
||||
// Debugging settings (use internally)
|
||||
_hideWhenOutofFocus: true, // Hide UI when the input is out of focus
|
||||
_logprocessingTime: false, // Log processing time for debugging
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -349,11 +349,11 @@ export function findAllTagPositions(text) {
|
||||
// Find the end of this tag (next comma or newline)
|
||||
let endPosComma = text.indexOf(',', startPos);
|
||||
let endPosNewline = text.indexOf('\n', startPos);
|
||||
let endPosPeriod = text.indexOf('.', startPos);
|
||||
let endPosPeriod = text.indexOf('.', startPos);
|
||||
|
||||
if (endPosComma === -1) endPosComma = text.length;
|
||||
if (endPosNewline === -1) endPosNewline = text.length;
|
||||
if (endPosPeriod === -1) endPosPeriod = text.length;
|
||||
if (endPosPeriod === -1) endPosPeriod = text.length;
|
||||
|
||||
const endPos = Math.min(endPosComma, endPosNewline, endPosPeriod);
|
||||
const tagText = text.substring(startPos, endPos);
|
||||
|
||||
Reference in New Issue
Block a user