WI custom order (slight return)

This commit is contained in:
Cohee
2023-11-11 20:16:57 +02:00
parent 30f723d9fc
commit 25b549b034
2 changed files with 26 additions and 13 deletions

View File

@@ -2502,6 +2502,7 @@
<input type="search" class="text_pole textarea_compact" data-i18n="[placeholder]Search..." id="world_info_search" placeholder="Search..."> <input type="search" class="text_pole textarea_compact" data-i18n="[placeholder]Search..." id="world_info_search" placeholder="Search...">
<select id="world_info_sort_order" class="margin0"> <select id="world_info_sort_order" class="margin0">
<option data-rule="priority" value="0">Priority</option> <option data-rule="priority" value="0">Priority</option>
<option data-rule="custom" value="13">Custom</option>
<option data-order="asc" data-field="comment" value="1">Title A-Z</option> <option data-order="asc" data-field="comment" value="1">Title A-Z</option>
<option data-order="desc" data-field="comment" value="2">Title Z-A</option> <option data-order="desc" data-field="comment" value="2">Title Z-A</option>
<option data-order="asc" data-field="content" data-rule="length" value="3">Tokens ↗</option> <option data-order="asc" data-field="content" data-rule="length" value="3">Tokens ↗</option>
@@ -3759,7 +3760,7 @@
<form class="world_entry_form wi-card-entry"> <form class="world_entry_form wi-card-entry">
<div class="inline-drawer wide100p"> <div class="inline-drawer wide100p">
<div class="inline-drawer-toggle inline-drawer-header gap5px padding0"> <div class="inline-drawer-toggle inline-drawer-header gap5px padding0">
<!-- <span class="drag-handle">&#9776;</span> --> <span class="drag-handle">&#9776;</span>
<div class="gap5px world_entry_thin_controls wide100p alignitemscenter"> <div class="gap5px world_entry_thin_controls wide100p alignitemscenter">
<div class="fa-fw fa-solid fa-circle-chevron-down inline-drawer-icon down"></div> <div class="fa-fw fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>
<span class="flex-container alignitemscenter wide100p"> <span class="flex-container alignitemscenter wide100p">

View File

@@ -269,7 +269,15 @@ function sortEntries(data) {
const sortRule = option.data('rule'); const sortRule = option.data('rule');
const orderSign = sortOrder === 'asc' ? 1 : -1; const orderSign = sortOrder === 'asc' ? 1 : -1;
if (sortRule === 'priority') { if (sortRule === 'custom') {
// First by display index, then by order, then by uid
data.sort((a, b) => {
const aValue = a.displayIndex;
const bValue = b.displayIndex;
return (aValue - bValue || b.order - a.order || a.uid - b.uid);
});
} else if (sortRule === 'priority') {
// First constant, then normal, then disabled. Then sort by order // First constant, then normal, then disabled. Then sort by order
data.sort((a, b) => { data.sort((a, b) => {
const aValue = a.constant ? 0 : a.disable ? 2 : 1; const aValue = a.constant ? 0 : a.disable ? 2 : 1;
@@ -375,7 +383,7 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) {
nextText: '>', nextText: '>',
formatNavigator: PAGINATION_TEMPLATE, formatNavigator: PAGINATION_TEMPLATE,
showNavigator: true, showNavigator: true,
callback: function (page) { callback: function (/** @type {object[]} */ page) {
$("#world_popup_entries_list").empty(); $("#world_popup_entries_list").empty();
const keywordHeaders = ` const keywordHeaders = `
<div id="WIEntryHeaderTitlesPC" class="flex-container wide100p spaceBetween justifyCenter textAlignCenter" style="padding:0 2.5em;"> <div id="WIEntryHeaderTitlesPC" class="flex-container wide100p spaceBetween justifyCenter textAlignCenter" style="padding:0 2.5em;">
@@ -399,6 +407,12 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) {
</small> </small>
</div>` </div>`
const blocks = page.map(entry => getWorldEntry(name, data, entry)).filter(x => x); const blocks = page.map(entry => getWorldEntry(name, data, entry)).filter(x => x);
const isCustomOrder = $('#world_info_sort_order').find(':selected').data('rule') === 'custom';
if (!isCustomOrder) {
blocks.forEach(block => {
block.find('.drag-handle').remove();
});
}
$("#world_popup_entries_list").append(keywordHeaders); $("#world_popup_entries_list").append(keywordHeaders);
$("#world_popup_entries_list").append(blocks); $("#world_popup_entries_list").append(blocks);
}, },
@@ -500,6 +514,8 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) {
delay: getSortableDelay(), delay: getSortableDelay(),
handle: ".drag-handle", handle: ".drag-handle",
stop: async function (event, ui) { stop: async function (event, ui) {
const firstEntryUid = $('#world_popup_entries_list .world_entry').first().data('uid');
const minDisplayIndex = data?.entries[firstEntryUid]?.displayIndex ?? 0;
$('#world_popup_entries_list .world_entry').each(function (index) { $('#world_popup_entries_list .world_entry').each(function (index) {
const uid = $(this).data('uid'); const uid = $(this).data('uid');
@@ -511,8 +527,8 @@ function displayWorldEntries(name, data, navigation = navigation_option.none) {
return; return;
} }
item.displayIndex = index; item.displayIndex = minDisplayIndex + index;
setOriginalDataValue(data, uid, 'extensions.display_index', index); setOriginalDataValue(data, uid, 'extensions.display_index', item.displayIndex);
}); });
console.table(Object.keys(data.entries).map(uid => data.entries[uid]).map(x => ({ uid: x.uid, key: x.key.join(','), displayIndex: x.displayIndex }))); console.table(Object.keys(data.entries).map(uid => data.entries[uid]).map(x => ({ uid: x.uid, key: x.key.join(','), displayIndex: x.displayIndex })));
@@ -1582,9 +1598,7 @@ async function checkWorldInfo(chat, maxContext) {
over_max = ( over_max = (
world_info_min_activations_depth_max > 0 && world_info_min_activations_depth_max > 0 &&
minActivationMsgIndex > world_info_min_activations_depth_max minActivationMsgIndex > world_info_min_activations_depth_max
) || ( ) || (minActivationMsgIndex >= chat.length)
minActivationMsgIndex >= chat.length
)
if (!over_max) { if (!over_max) {
needsToScan = true needsToScan = true
textToScan = transformString(chat.slice(minActivationMsgIndex, minActivationMsgIndex + 1).join("")); textToScan = transformString(chat.slice(minActivationMsgIndex, minActivationMsgIndex + 1).join(""));
@@ -2167,11 +2181,9 @@ jQuery(() => {
updateEditor(navigation_option.previous); updateEditor(navigation_option.previous);
}); });
$('#world_info_sort_order').on('change', function (e) { $('#world_info_sort_order').on('change', function () {
if (e.target instanceof HTMLOptionElement) { const value = String($(this).find(":selected").val());
localStorage.setItem(SORT_ORDER_KEY, e.target.value); localStorage.setItem(SORT_ORDER_KEY, value);
}
updateEditor(navigation_option.none); updateEditor(navigation_option.none);
}) })