WI world search allows quick-select

This commit is contained in:
Wolfsblvt 2024-05-02 20:04:24 +02:00
parent f796387e7e
commit f0adbc3c28
2 changed files with 29 additions and 0 deletions

View File

@ -196,3 +196,14 @@
.WIEntryHeaderTitleMobile {
display: none;
}
#world_info+span.select2-container .select2-selection__choice__display {
cursor: pointer;
margin-left: 1px; /* Fix weird alignment on the left side */
}
#world_info+span.select2-container .select2-selection__choice__display:hover {
background-color: #f1f1f1;
color: #333;
outline: none;
}

View File

@ -379,6 +379,7 @@ function setWorldInfoSettings(settings, data) {
});
$('#world_info_sort_order').val(localStorage.getItem(SORT_ORDER_KEY) || '0');
$('#world_info').trigger('change');
$('#world_editor_select').trigger('change');
eventSource.on(event_types.CHAT_CHANGED, () => {
@ -3114,6 +3115,23 @@ jQuery(() => {
allowClear: true,
closeOnSelect: false,
});
// Subscribe world loading to the select2 multiselect items (We need to target the specific select2 control)
$('#world_info + span.select2-container').on('click', function (event) {
if ($(event.target).hasClass('select2-selection__choice__display')) {
event.preventDefault();
// select2 still bubbles the event to open the dropdown. So we close it here
$('#world_info').select2('close');
const name = $(event.target).text();
const selectedIndex = world_names.indexOf(name);
if (selectedIndex !== -1) {
$('#world_editor_select').val(selectedIndex).trigger('change');
console.log('Quick selection of world', name);
}
}
});
}
$('#WorldInfo').on('scroll', () => {