diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index b56087835..ce55c091d 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1,7 +1,7 @@ import { Fuse } from '../lib.js'; import { saveSettings, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js'; -import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce, findChar, onlyUnique, equalsIgnoreCaseAndAccents } from './utils.js'; +import { download, debounce, delay, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, getSanitizedFilename, checkOverwriteExistingData, getStringHash, parseStringArray, cancelDebounce, findChar, onlyUnique, equalsIgnoreCaseAndAccents } from './utils.js'; import { extension_settings, getContext } from './extensions.js'; import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js'; import { isMobile } from './RossAscends-mods.js'; @@ -1754,12 +1754,12 @@ function registerWorldInfoSlashCommands() { */ export async function showWorldEditor(name) { if (!name) { - hideWorldEditor(); + await hideWorldEditor(); return; } const wiData = await loadWorldInfo(name); - displayWorldEntries(name, wiData); + await displayWorldEntries(name, wiData); } /** @@ -1815,8 +1815,8 @@ export async function updateWorldInfoList() { } } -function hideWorldEditor() { - displayWorldEntries(null, null); +async function hideWorldEditor() { + await displayWorldEntries(null, null); } function getWIElement(name) { @@ -1937,15 +1937,102 @@ function updateWorldEntryKeyOptionsCache(keyOptions, { remove = false, reset = f worldEntryKeyOptionsCache.sort((a, b) => b.count - a.count || a.text.localeCompare(b.text)); } -function displayWorldEntries(name, data, navigation = navigation_option.none, flashOnNav = true) { - updateEditor = (navigation, flashOnNav = true) => displayWorldEntries(name, data, navigation, flashOnNav); +function clearEntryList() { + console.time('clearEntryList'); + const $list = $('#world_popup_entries_list'); + + + if (!$list.children().length) { + console.warn('List already empty, skipping cleanup.'); + console.timeEnd('clearEntryList'); + return; + } + + // Step 1: Clean all