Compare commits

...
4 Commits
6 changed files with 37 additions and 10 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
[project] [project]
name = "comfyui-autocomplete-plus" name = "comfyui-autocomplete-plus"
description = "Autocomplete and Related Tag display for ComfyUI" description = "Autocomplete and Related Tag display for ComfyUI"
version = "1.2.0" version = "1.2.1"
license = {file = "LICENSE"} license = {file = "LICENSE"}
dependencies = ["",] dependencies = ["",]
+5 -2
View File
@@ -5,9 +5,10 @@ import {
getEnabledTagSourceInPriorityOrder getEnabledTagSourceInPriorityOrder
} from './data.js'; } from './data.js';
import { import {
formatCountHumanReadable, isLongText,
hiraToKata, hiraToKata,
kataToHira, kataToHira,
formatCountHumanReadable,
isContainsLetterOrNumber, isContainsLetterOrNumber,
normalizeTagToInsert, normalizeTagToInsert,
normalizeTagToSearch, normalizeTagToSearch,
@@ -82,7 +83,9 @@ function searchCompletionCandidates(textareaElement) {
const ESCAPE_SEQUENCE = ["#", "/"]; // If the first string is that character, autocomplete will not be displayed. const ESCAPE_SEQUENCE = ["#", "/"]; // If the first string is that character, autocomplete will not be displayed.
const partialTag = getCurrentPartialTag(textareaElement); const partialTag = getCurrentPartialTag(textareaElement);
if (!partialTag || partialTag.length <= 0 || ESCAPE_SEQUENCE.some(seq => partialTag.startsWith(seq))) { if (!partialTag || partialTag.length <= 0 ||
ESCAPE_SEQUENCE.some(seq => partialTag.startsWith(seq)) ||
isLongText(partialTag)) {
return []; // No valid input for autocomplete return []; // No valid input for autocomplete
} }
+3 -2
View File
@@ -1,4 +1,4 @@
import { settingValues } from "./settings.js"; import { settingValues, updateMaxTagLength } from "./settings.js";
// --- Constants --- // --- Constants ---
@@ -158,6 +158,8 @@ async function loadTags(csvUrl, siteName) {
// Create a TagData instance instead of a plain object // Create a TagData instance instead of a plain object
const tagData = new TagData(tag, aliases, category, count, siteName); const tagData = new TagData(tag, aliases, category, count, siteName);
updateMaxTagLength(tag.length);
autoCompleteData[siteName].sortedTags.push(tagData); autoCompleteData[siteName].sortedTags.push(tagData);
} else { } else {
console.warn(`[Autocomplete-Plus] Invalid CSV format in line ${i + 1} of ${csvUrl}: ${line}. Expected ${TAGS_CSV_HEADER_COLUMNS.length} columns, but got ${columns.length}.`); console.warn(`[Autocomplete-Plus] Invalid CSV format in line ${i + 1} of ${csvUrl}: ${line}. Expected ${TAGS_CSV_HEADER_COLUMNS.length} columns, but got ${columns.length}.`);
@@ -326,7 +328,6 @@ export async function initializeData(csvListData, source) {
const startTime = performance.now(); const startTime = performance.now();
autoCompleteData[source].isInitializing = true; autoCompleteData[source].isInitializing = true;
// console.log("[Autocomplete-Plus] Initializing autocomplete data...");
try { try {
// Store functions that return Promises (Promise Factories) // Store functions that return Promises (Promise Factories)
+4 -3
View File
@@ -1,13 +1,14 @@
import { TagSource, TagCategory, TagData, autoCompleteData } from './data.js'; import { TagCategory, TagData, TagSource, autoCompleteData } from './data.js';
import { settingValues } from './settings.js'; import { settingValues } from './settings.js';
import { import {
extractTagsFromTextArea, extractTagsFromTextArea,
findAllTagPositions, findAllTagPositions,
getCurrentTagRange,
getViewportMargin, getViewportMargin,
isLongText,
isValidTag, isValidTag,
normalizeTagToInsert, normalizeTagToInsert,
normalizeTagToSearch, normalizeTagToSearch,
getCurrentTagRange,
} from './utils.js'; } from './utils.js';
// --- RelatedTags Logic --- // --- RelatedTags Logic ---
@@ -309,7 +310,7 @@ class RelatedTagsUI {
const currentTag = getTagFromCursorPosition(textareaElement); const currentTag = getTagFromCursorPosition(textareaElement);
if (!this.isPinned) { if (!this.isPinned) {
if (isValidTag(currentTag)) { if (!isLongText(currentTag) && isValidTag(currentTag)) {
this.currentTag = currentTag this.currentTag = currentTag
} else { } else {
this.hide(); this.hide();
+11
View File
@@ -17,8 +17,19 @@ export const settingValues = {
// Internal logic settings // Internal logic settings
_useFallbackAttachmentForEventListener: false, // Fallback to attach event listener when somthing goes wrong _useFallbackAttachmentForEventListener: false, // Fallback to attach event listener when somthing goes wrong
_maxTagLength: 100, // Maximum tag length to prevent performance issues with long text input
// Debugging settings (use internally) // Debugging settings (use internally)
_hideWhenOutofFocus: true, // Hide UI when the input is out of focus _hideWhenOutofFocus: true, // Hide UI when the input is out of focus
_logprocessingTime: false, // Log processing time for debugging _logprocessingTime: false, // Log processing time for debugging
} }
/**
* Update the maximum tag length setting value.
* This function ensures that the maximum tag length is always at least as long as the new length provided.
* @param {number} newLength
*/
export function updateMaxTagLength(newLength) {
if(isNaN(newLength)) return;
settingValues._maxTagLength = Math.max(settingValues._maxTagLength, newLength);
}
+11
View File
@@ -1,3 +1,5 @@
import { settingValues } from './settings.js';
// --- Html String constants --- // --- Html String constants ---
/** /**
@@ -44,6 +46,15 @@ const REG_STRIP_TRAILING_PAREN = /(.*)(?<!\\)\)$/s;
const REG_WILDCARD_WEIGHTED_TAG = /(\d+)[_\s]*::(.*?)(?=\||$)/g; const REG_WILDCARD_WEIGHTED_TAG = /(\d+)[_\s]*::(.*?)(?=\||$)/g;
const REG_WILDCARD_SIMPLE_WORD = /[^{}_|]+/g; const REG_WILDCARD_SIMPLE_WORD = /[^{}_|]+/g;
/**
* Checks if the input text is longer than the maximum allowed tag length.
* @param {string} text The text to check.
* @return {boolean} True if the text is longer than the maximum tag length, false otherwise.
*/
export function isLongText(text) {
return text?.length > settingValues._maxTagLength;
}
/** /**
* Converts Hiragana to Katakana. * Converts Hiragana to Katakana.
* @param {string} str Input string. * @param {string} str Input string.