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="WIEntryTitleAndStatus flex-container flex1 alignitemscenter">
<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>
<!-- <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">
@ -4901,7 +4901,7 @@
</span>
</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 class="world_entry_form_control">
<small class="textAlignCenter" data-i18n="Logic">Logic</small>
@ -4920,7 +4920,7 @@
</small>
<small class="textAlignCenter" data-i18n="Optional Filter">Optional Filter</small>
<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>

View File

@ -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: