From 3a0ceae80aaf20979fc4e90621942f6e196c5a31 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:45:28 +0300 Subject: [PATCH] Optimize scroll height resets on WI entry render, remove silly logs --- public/index.html | 6 ++--- public/scripts/world-info.js | 47 +++++++++++++++--------------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/public/index.html b/public/index.html index 674403e6e..e807b3d67 100644 --- a/public/index.html +++ b/public/index.html @@ -4838,7 +4838,7 @@
- +
+
Logic @@ -4920,7 +4920,7 @@ Optional Filter
- +
diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 83d4a1727..ae601bcea 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -42,6 +42,8 @@ const world_info_logic = { AND_ALL: 3, }; +const WI_ENTRY_EDIT_TEMPLATE = $('#entry_edit_template .world_entry'); + let world_info = {}; let selected_world_info = []; let world_names; @@ -799,6 +801,11 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) { afterSizeSelectorChange: function (e) { localStorage.setItem(storageKey, e.target.value); }, + afterPaging: function () { + $('#world_popup_entries_list textarea[name="comment"]').each(function () { + initScrollHeight($(this)); + }); + }, }); if (typeof navigation === 'number' && Number(navigation) >= 0) { @@ -986,7 +993,7 @@ function getWorldEntry(name, data, entry) { return; } - const template = $('#entry_edit_template .world_entry').clone(); + const template = WI_ENTRY_EDIT_TEMPLATE.clone(); template.data('uid', entry.uid); template.attr('uid', entry.uid); @@ -998,10 +1005,10 @@ function getWorldEntry(name, data, entry) { event.stopPropagation(); }); - keyInput.on('input', function () { + keyInput.on('input', function (_, { skipReset } = {}) { const uid = $(this).data('uid'); const value = String($(this).val()); - resetScrollHeight(this); + !skipReset && resetScrollHeight(this); data.entries[uid].key = value .split(',') .map((x) => x.trim()) @@ -1010,7 +1017,7 @@ function getWorldEntry(name, data, entry) { setOriginalDataValue(data, uid, 'keys', data.entries[uid].key); saveWorldInfo(name, data); }); - keyInput.val(entry.key.join(', ')).trigger('input'); + keyInput.val(entry.key.join(', ')).trigger('input', { skipReset: true }); //initScrollHeight(keyInput); // logic AND/NOT @@ -1024,7 +1031,6 @@ function getWorldEntry(name, data, entry) { selectiveLogicDropdown.on('input', function () { const uid = $(this).data('uid'); const value = Number($(this).val()); - console.debug(`logic for ${entry.uid} set to ${value}`); data.entries[uid].selectiveLogic = !isNaN(value) ? value : world_info_logic.AND_ANY; setOriginalDataValue(data, uid, 'selectiveLogic', data.entries[uid].selectiveLogic); saveWorldInfo(name, data); @@ -1134,10 +1140,10 @@ function getWorldEntry(name, data, entry) { // keysecondary const keySecondaryInput = template.find('textarea[name="keysecondary"]'); keySecondaryInput.data('uid', entry.uid); - keySecondaryInput.on('input', function () { + keySecondaryInput.on('input', function (_, { skipReset } = {}) { const uid = $(this).data('uid'); const value = String($(this).val()); - resetScrollHeight(this); + !skipReset && resetScrollHeight(this); data.entries[uid].keysecondary = value .split(',') .map((x) => x.trim()) @@ -1147,17 +1153,17 @@ function getWorldEntry(name, data, entry) { saveWorldInfo(name, data); }); - keySecondaryInput.val(entry.keysecondary.join(', ')).trigger('input'); - initScrollHeight(keySecondaryInput); + keySecondaryInput.val(entry.keysecondary.join(', ')).trigger('input', { skipReset: true }); + //initScrollHeight(keySecondaryInput); // comment const commentInput = template.find('textarea[name="comment"]'); const commentToggle = template.find('input[name="addMemo"]'); commentInput.data('uid', entry.uid); - commentInput.on('input', function () { + commentInput.on('input', function (_, { skipReset } = {}) { const uid = $(this).data('uid'); const value = $(this).val(); - resetScrollHeight(this); + !skipReset && resetScrollHeight(this); data.entries[uid].comment = value; setOriginalDataValue(data, uid, 'comment', data.entries[uid].comment); @@ -1176,8 +1182,8 @@ function getWorldEntry(name, data, entry) { value ? commentContainer.show() : commentContainer.hide(); }); - commentInput.val(entry.comment).trigger('input'); - initScrollHeight(commentInput); + commentInput.val(entry.comment).trigger('input', { skipReset: true }); + //initScrollHeight(commentInput); commentToggle.prop('checked', true /* entry.addMemo */).trigger('input'); commentToggle.parent().hide(); @@ -1378,7 +1384,7 @@ function getWorldEntry(name, data, entry) { } const positionInput = template.find('select[name="position"]'); - initScrollHeight(positionInput); + //initScrollHeight(positionInput); positionInput.data('uid', entry.uid); positionInput.on('click', function (event) { // Prevent closing the drawer on clicking the input @@ -1435,7 +1441,6 @@ function getWorldEntry(name, data, entry) { //new tri-state selector for constant/normal/disabled const entryStateSelector = template.find('select[name="entryStateSelector"]'); entryStateSelector.data('uid', entry.uid); - console.log(entry.uid); entryStateSelector.on('click', function (event) { // Prevent closing the drawer on clicking the input event.stopPropagation(); @@ -1450,7 +1455,6 @@ function getWorldEntry(name, data, entry) { setOriginalDataValue(data, uid, 'enabled', true); setOriginalDataValue(data, uid, 'constant', true); template.removeClass('disabledWIEntry'); - console.debug('set to constant'); break; case 'normal': data.entries[uid].constant = false; @@ -1458,7 +1462,6 @@ function getWorldEntry(name, data, entry) { setOriginalDataValue(data, uid, 'enabled', true); setOriginalDataValue(data, uid, 'constant', false); template.removeClass('disabledWIEntry'); - console.debug('set to normal'); break; case 'disabled': data.entries[uid].constant = false; @@ -1466,7 +1469,6 @@ function getWorldEntry(name, data, entry) { setOriginalDataValue(data, uid, 'enabled', false); setOriginalDataValue(data, uid, 'constant', false); template.addClass('disabledWIEntry'); - console.debug('set to disabled'); break; } saveWorldInfo(name, data); @@ -1474,19 +1476,13 @@ function getWorldEntry(name, data, entry) { }); const entryState = function () { - - console.log(`constant: ${entry.constant}, disabled: ${entry.disable}`); if (entry.constant === true) { - console.debug('found constant'); return 'constant'; } else if (entry.disable === true) { - console.debug('found disabled'); return 'disabled'; } else { - console.debug('found normal'); return 'normal'; } - }; template .find(`select[name="entryStateSelector"] option[value=${entryState()}]`) @@ -1982,15 +1978,12 @@ async function getSortedEntries() { switch (Number(world_info_character_strategy)) { case world_info_insertion_strategy.evenly: - console.debug('WI using evenly'); entries = [...globalLore, ...characterLore].sort(sortFn); break; case world_info_insertion_strategy.character_first: - console.debug('WI using char first'); entries = [...characterLore.sort(sortFn), ...globalLore.sort(sortFn)]; break; case world_info_insertion_strategy.global_first: - console.debug('WI using global first'); entries = [...globalLore.sort(sortFn), ...characterLore.sort(sortFn)]; break; default: