diff --git a/web/js/autocomplete.js b/web/js/autocomplete.js index 91901fe..638cc05 100644 --- a/web/js/autocomplete.js +++ b/web/js/autocomplete.js @@ -5,9 +5,10 @@ import { getEnabledTagSourceInPriorityOrder } from './data.js'; import { - formatCountHumanReadable, + isLongText, hiraToKata, kataToHira, + formatCountHumanReadable, isContainsLetterOrNumber, normalizeTagToInsert, normalizeTagToSearch, @@ -82,8 +83,10 @@ function searchCompletionCandidates(textareaElement) { const ESCAPE_SEQUENCE = ["#", "/"]; // If the first string is that character, autocomplete will not be displayed. const partialTag = getCurrentPartialTag(textareaElement); - if (!partialTag || partialTag.length <= 0 || ESCAPE_SEQUENCE.some(seq => partialTag.startsWith(seq))) { - return []; // No valid input for autocomplete + if (!partialTag || partialTag.length <= 0 || + ESCAPE_SEQUENCE.some(seq => partialTag.startsWith(seq)) || + isLongText(partialTag)) { + return []; // No valid input for autocomplete } const exactMatches = []; diff --git a/web/js/data.js b/web/js/data.js index 0f57bfb..cd1e4f5 100644 --- a/web/js/data.js +++ b/web/js/data.js @@ -1,4 +1,4 @@ -import { settingValues } from "./settings.js"; +import { settingValues, updateMaxTagLength } from "./settings.js"; // --- Constants --- @@ -158,6 +158,8 @@ async function loadTags(csvUrl, siteName) { // Create a TagData instance instead of a plain object const tagData = new TagData(tag, aliases, category, count, siteName); + updateMaxTagLength(tag.length); + autoCompleteData[siteName].sortedTags.push(tagData); } 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}.`); @@ -326,7 +328,6 @@ export async function initializeData(csvListData, source) { const startTime = performance.now(); autoCompleteData[source].isInitializing = true; - // console.log("[Autocomplete-Plus] Initializing autocomplete data..."); try { // Store functions that return Promises (Promise Factories) diff --git a/web/js/related-tags.js b/web/js/related-tags.js index e1f779e..b68b5a8 100644 --- a/web/js/related-tags.js +++ b/web/js/related-tags.js @@ -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 { extractTagsFromTextArea, findAllTagPositions, + getCurrentTagRange, getViewportMargin, + isLongText, isValidTag, normalizeTagToInsert, normalizeTagToSearch, - getCurrentTagRange, } from './utils.js'; // --- RelatedTags Logic --- @@ -309,7 +310,7 @@ class RelatedTagsUI { const currentTag = getTagFromCursorPosition(textareaElement); if (!this.isPinned) { - if (isValidTag(currentTag)) { + if (!isLongText(currentTag) && isValidTag(currentTag)) { this.currentTag = currentTag } else { this.hide(); diff --git a/web/js/settings.js b/web/js/settings.js index 6b93e98..4342852 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -17,8 +17,19 @@ export const settingValues = { // Internal logic settings _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) _hideWhenOutofFocus: true, // Hide UI when the input is out of focus _logprocessingTime: false, // Log processing time for debugging -} \ No newline at end of file +} + +/** + * 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); +} diff --git a/web/js/utils.js b/web/js/utils.js index ac0246d..203fbc2 100644 --- a/web/js/utils.js +++ b/web/js/utils.js @@ -1,3 +1,5 @@ +import { settingValues } from './settings.js'; + // --- Html String constants --- /** @@ -44,6 +46,15 @@ const REG_STRIP_TRAILING_PAREN = /(.*)(? settingValues._maxTagLength; +} + /** * Converts Hiragana to Katakana. * @param {string} str Input string.