Merge pull request #3790 from WoodyLetsCode/fix-preset-sorting

Fix preset sorting
This commit is contained in:
Blaž Kristan 2024-03-05 11:38:26 +01:00 committed by GitHub
commit a6d58ee360
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2794,7 +2794,12 @@ function search(field, listId = null) {
if (!listId) return;
const search = field.value !== '';
const presets = listId === 'pcont';
// restore default preset sorting if no search term is entered
if (listId === 'pcont' && !search) {
populatePresets();
return;
}
// clear filter if searching in fxlist
if (listId === 'fxlist' && search) {
@ -2806,7 +2811,7 @@ function search(field, listId = null) {
const listItems = gId(listId).querySelectorAll('.lstI');
// filter list items but leave (Default & Solid) always visible
for (i = (presets ? 0 : 1); i < listItems.length; i++) {
for (i = (listId === 'pcont' ? 0 : 1); i < listItems.length; i++) {
const listItem = listItems[i];
const listItemName = listItem.querySelector('.lstIname').innerText.toUpperCase();
const searchIndex = listItemName.indexOf(field.value.toUpperCase());
@ -2814,7 +2819,6 @@ function search(field, listId = null) {
listItem.dataset.searchIndex = searchIndex;
}
if (!presets) {
// sort list items by search index and name
const sortedListItems = Array.from(listItems).sort((a, b) => {
const aSearchIndex = parseInt(a.dataset.searchIndex);
@ -2838,7 +2842,6 @@ function search(field, listId = null) {
if (firstVisibleItem && search) {
firstVisibleItem.scrollIntoView({ behavior: "instant", block: "center" });
}
}
}
function clean(clearButton) {