Optimize scroll height resets on WI entry render, remove silly logs

This commit is contained in:
Cohee 2024-04-05 13:45:28 +03:00
parent 8f6e41428f
commit 3a0ceae80a
2 changed files with 23 additions and 30 deletions

View File

@ -4838,7 +4838,7 @@
<div class="flex-container alignitemscenter wide100p"> <div class="flex-container alignitemscenter wide100p">
<div class="WIEntryTitleAndStatus flex-container flex1 alignitemscenter"> <div class="WIEntryTitleAndStatus flex-container flex1 alignitemscenter">
<div class="flex-container flex1"> <div class="flex-container flex1">
<textarea class="text_pole autoSetHeight" name="comment" maxlength="5000" data-i18n="[placeholder]Entry Title/Memo" placeholder="Entry Title/Memo"></textarea> <textarea class="text_pole" rows="1" name="comment" maxlength="5000" data-i18n="[placeholder]Entry Title/Memo" placeholder="Entry Title/Memo"></textarea>
</div> </div>
<!-- <span class="world_entry_form_position_value"></span> --> <!-- <span class="world_entry_form_position_value"></span> -->
<select data-i18n="[title]WI Entry Status:🔵 Constant🟢 Normal❌ Disabled" title="WI Entry Status:&#13;🔵 Constant&#13;🟢 Normal&#13;❌ Disabled" name="entryStateSelector" class="text_pole widthNatural margin0"> <select data-i18n="[title]WI Entry Status:🔵 Constant🟢 Normal❌ Disabled" title="WI Entry Status:&#13;🔵 Constant&#13;🟢 Normal&#13;❌ Disabled" name="entryStateSelector" class="text_pole widthNatural margin0">
@ -4901,7 +4901,7 @@
</span> </span>
</small> </small>
<small class="textAlignCenter" data-i18n="Primary Keywords">Primary Keywords</small> <small class="textAlignCenter" data-i18n="Primary Keywords">Primary Keywords</small>
<textarea class="text_pole keyprimarytextpole" name="key" rows="1" data-i18n="[placeholder]Comma separated (required)" placeholder="Comma separated (required)" maxlength="2000"></textarea> <textarea class="text_pole keyprimarytextpole autoSetHeight" name="key" rows="1" data-i18n="[placeholder]Comma separated (required)" placeholder="Comma separated (required)" maxlength="2000"></textarea>
</div> </div>
<div class="world_entry_form_control"> <div class="world_entry_form_control">
<small class="textAlignCenter" data-i18n="Logic">Logic</small> <small class="textAlignCenter" data-i18n="Logic">Logic</small>
@ -4920,7 +4920,7 @@
</small> </small>
<small class="textAlignCenter" data-i18n="Optional Filter">Optional Filter</small> <small class="textAlignCenter" data-i18n="Optional Filter">Optional Filter</small>
<div class="flex-container flexFlowRow alignitemscenter"> <div class="flex-container flexFlowRow alignitemscenter">
<textarea class="text_pole keysecondarytextpole" name="keysecondary" rows="1" data-i18n="[placeholder]Comma separated (ignored if empty)" placeholder="Comma separated list" maxlength="2000"></textarea> <textarea class="text_pole keysecondarytextpole autoSetHeight" name="keysecondary" rows="1" data-i18n="[placeholder]Comma separated (ignored if empty)" placeholder="Comma separated list" maxlength="2000"></textarea>
</div> </div>
</div> </div>
</div> </div>

View File

@ -42,6 +42,8 @@ const world_info_logic = {
AND_ALL: 3, AND_ALL: 3,
}; };
const WI_ENTRY_EDIT_TEMPLATE = $('#entry_edit_template .world_entry');
let world_info = {}; let world_info = {};
let selected_world_info = []; let selected_world_info = [];
let world_names; let world_names;
@ -799,6 +801,11 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) {
afterSizeSelectorChange: function (e) { afterSizeSelectorChange: function (e) {
localStorage.setItem(storageKey, e.target.value); 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) { if (typeof navigation === 'number' && Number(navigation) >= 0) {
@ -986,7 +993,7 @@ function getWorldEntry(name, data, entry) {
return; return;
} }
const template = $('#entry_edit_template .world_entry').clone(); const template = WI_ENTRY_EDIT_TEMPLATE.clone();
template.data('uid', entry.uid); template.data('uid', entry.uid);
template.attr('uid', entry.uid); template.attr('uid', entry.uid);
@ -998,10 +1005,10 @@ function getWorldEntry(name, data, entry) {
event.stopPropagation(); event.stopPropagation();
}); });
keyInput.on('input', function () { keyInput.on('input', function (_, { skipReset } = {}) {
const uid = $(this).data('uid'); const uid = $(this).data('uid');
const value = String($(this).val()); const value = String($(this).val());
resetScrollHeight(this); !skipReset && resetScrollHeight(this);
data.entries[uid].key = value data.entries[uid].key = value
.split(',') .split(',')
.map((x) => x.trim()) .map((x) => x.trim())
@ -1010,7 +1017,7 @@ function getWorldEntry(name, data, entry) {
setOriginalDataValue(data, uid, 'keys', data.entries[uid].key); setOriginalDataValue(data, uid, 'keys', data.entries[uid].key);
saveWorldInfo(name, data); saveWorldInfo(name, data);
}); });
keyInput.val(entry.key.join(', ')).trigger('input'); keyInput.val(entry.key.join(', ')).trigger('input', { skipReset: true });
//initScrollHeight(keyInput); //initScrollHeight(keyInput);
// logic AND/NOT // logic AND/NOT
@ -1024,7 +1031,6 @@ function getWorldEntry(name, data, entry) {
selectiveLogicDropdown.on('input', function () { selectiveLogicDropdown.on('input', function () {
const uid = $(this).data('uid'); const uid = $(this).data('uid');
const value = Number($(this).val()); 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; data.entries[uid].selectiveLogic = !isNaN(value) ? value : world_info_logic.AND_ANY;
setOriginalDataValue(data, uid, 'selectiveLogic', data.entries[uid].selectiveLogic); setOriginalDataValue(data, uid, 'selectiveLogic', data.entries[uid].selectiveLogic);
saveWorldInfo(name, data); saveWorldInfo(name, data);
@ -1134,10 +1140,10 @@ function getWorldEntry(name, data, entry) {
// keysecondary // keysecondary
const keySecondaryInput = template.find('textarea[name="keysecondary"]'); const keySecondaryInput = template.find('textarea[name="keysecondary"]');
keySecondaryInput.data('uid', entry.uid); keySecondaryInput.data('uid', entry.uid);
keySecondaryInput.on('input', function () { keySecondaryInput.on('input', function (_, { skipReset } = {}) {
const uid = $(this).data('uid'); const uid = $(this).data('uid');
const value = String($(this).val()); const value = String($(this).val());
resetScrollHeight(this); !skipReset && resetScrollHeight(this);
data.entries[uid].keysecondary = value data.entries[uid].keysecondary = value
.split(',') .split(',')
.map((x) => x.trim()) .map((x) => x.trim())
@ -1147,17 +1153,17 @@ function getWorldEntry(name, data, entry) {
saveWorldInfo(name, data); saveWorldInfo(name, data);
}); });
keySecondaryInput.val(entry.keysecondary.join(', ')).trigger('input'); keySecondaryInput.val(entry.keysecondary.join(', ')).trigger('input', { skipReset: true });
initScrollHeight(keySecondaryInput); //initScrollHeight(keySecondaryInput);
// comment // comment
const commentInput = template.find('textarea[name="comment"]'); const commentInput = template.find('textarea[name="comment"]');
const commentToggle = template.find('input[name="addMemo"]'); const commentToggle = template.find('input[name="addMemo"]');
commentInput.data('uid', entry.uid); commentInput.data('uid', entry.uid);
commentInput.on('input', function () { commentInput.on('input', function (_, { skipReset } = {}) {
const uid = $(this).data('uid'); const uid = $(this).data('uid');
const value = $(this).val(); const value = $(this).val();
resetScrollHeight(this); !skipReset && resetScrollHeight(this);
data.entries[uid].comment = value; data.entries[uid].comment = value;
setOriginalDataValue(data, uid, 'comment', data.entries[uid].comment); setOriginalDataValue(data, uid, 'comment', data.entries[uid].comment);
@ -1176,8 +1182,8 @@ function getWorldEntry(name, data, entry) {
value ? commentContainer.show() : commentContainer.hide(); value ? commentContainer.show() : commentContainer.hide();
}); });
commentInput.val(entry.comment).trigger('input'); commentInput.val(entry.comment).trigger('input', { skipReset: true });
initScrollHeight(commentInput); //initScrollHeight(commentInput);
commentToggle.prop('checked', true /* entry.addMemo */).trigger('input'); commentToggle.prop('checked', true /* entry.addMemo */).trigger('input');
commentToggle.parent().hide(); commentToggle.parent().hide();
@ -1378,7 +1384,7 @@ function getWorldEntry(name, data, entry) {
} }
const positionInput = template.find('select[name="position"]'); const positionInput = template.find('select[name="position"]');
initScrollHeight(positionInput); //initScrollHeight(positionInput);
positionInput.data('uid', entry.uid); positionInput.data('uid', entry.uid);
positionInput.on('click', function (event) { positionInput.on('click', function (event) {
// Prevent closing the drawer on clicking the input // 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 //new tri-state selector for constant/normal/disabled
const entryStateSelector = template.find('select[name="entryStateSelector"]'); const entryStateSelector = template.find('select[name="entryStateSelector"]');
entryStateSelector.data('uid', entry.uid); entryStateSelector.data('uid', entry.uid);
console.log(entry.uid);
entryStateSelector.on('click', function (event) { entryStateSelector.on('click', function (event) {
// Prevent closing the drawer on clicking the input // Prevent closing the drawer on clicking the input
event.stopPropagation(); event.stopPropagation();
@ -1450,7 +1455,6 @@ function getWorldEntry(name, data, entry) {
setOriginalDataValue(data, uid, 'enabled', true); setOriginalDataValue(data, uid, 'enabled', true);
setOriginalDataValue(data, uid, 'constant', true); setOriginalDataValue(data, uid, 'constant', true);
template.removeClass('disabledWIEntry'); template.removeClass('disabledWIEntry');
console.debug('set to constant');
break; break;
case 'normal': case 'normal':
data.entries[uid].constant = false; data.entries[uid].constant = false;
@ -1458,7 +1462,6 @@ function getWorldEntry(name, data, entry) {
setOriginalDataValue(data, uid, 'enabled', true); setOriginalDataValue(data, uid, 'enabled', true);
setOriginalDataValue(data, uid, 'constant', false); setOriginalDataValue(data, uid, 'constant', false);
template.removeClass('disabledWIEntry'); template.removeClass('disabledWIEntry');
console.debug('set to normal');
break; break;
case 'disabled': case 'disabled':
data.entries[uid].constant = false; data.entries[uid].constant = false;
@ -1466,7 +1469,6 @@ function getWorldEntry(name, data, entry) {
setOriginalDataValue(data, uid, 'enabled', false); setOriginalDataValue(data, uid, 'enabled', false);
setOriginalDataValue(data, uid, 'constant', false); setOriginalDataValue(data, uid, 'constant', false);
template.addClass('disabledWIEntry'); template.addClass('disabledWIEntry');
console.debug('set to disabled');
break; break;
} }
saveWorldInfo(name, data); saveWorldInfo(name, data);
@ -1474,19 +1476,13 @@ function getWorldEntry(name, data, entry) {
}); });
const entryState = function () { const entryState = function () {
console.log(`constant: ${entry.constant}, disabled: ${entry.disable}`);
if (entry.constant === true) { if (entry.constant === true) {
console.debug('found constant');
return 'constant'; return 'constant';
} else if (entry.disable === true) { } else if (entry.disable === true) {
console.debug('found disabled');
return 'disabled'; return 'disabled';
} else { } else {
console.debug('found normal');
return 'normal'; return 'normal';
} }
}; };
template template
.find(`select[name="entryStateSelector"] option[value=${entryState()}]`) .find(`select[name="entryStateSelector"] option[value=${entryState()}]`)
@ -1982,15 +1978,12 @@ async function getSortedEntries() {
switch (Number(world_info_character_strategy)) { switch (Number(world_info_character_strategy)) {
case world_info_insertion_strategy.evenly: case world_info_insertion_strategy.evenly:
console.debug('WI using evenly');
entries = [...globalLore, ...characterLore].sort(sortFn); entries = [...globalLore, ...characterLore].sort(sortFn);
break; break;
case world_info_insertion_strategy.character_first: case world_info_insertion_strategy.character_first:
console.debug('WI using char first');
entries = [...characterLore.sort(sortFn), ...globalLore.sort(sortFn)]; entries = [...characterLore.sort(sortFn), ...globalLore.sort(sortFn)];
break; break;
case world_info_insertion_strategy.global_first: case world_info_insertion_strategy.global_first:
console.debug('WI using global first');
entries = [...globalLore.sort(sortFn), ...characterLore.sort(sortFn)]; entries = [...globalLore.sort(sortFn), ...characterLore.sort(sortFn)];
break; break;
default: default: