Merge pull request #2175 from Wolfsblvt/wi-search-quickselect

WI world search allows quick-select
This commit is contained in:
Cohee 2024-05-02 22:51:24 +03:00 committed by GitHub
commit 73bea1f454
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View File

@ -196,3 +196,21 @@
.WIEntryHeaderTitleMobile {
display: none;
}
#world_info+span.select2-container .select2-selection__choice__remove,
#world_info+span.select2-container .select2-selection__choice__display {
cursor: pointer;
transition: background-color 0.3s;
color: var(--SmartThemeBodyColor);
background-color: var(--black50a);
}
#world_info+span.select2-container .select2-selection__choice__display {
/* Fix weird alignment on the left side */
margin-left: 1px;
}
#world_info+span.select2-container .select2-selection__choice__remove:hover,
#world_info+span.select2-container .select2-selection__choice__display:hover {
background-color: var(--white30a);
}

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', () => {