Refactor ensureSelectionExists for more readability

This commit is contained in:
Cohee 2024-10-01 14:28:34 +03:00
parent 42d24dbc47
commit ab966db1e5

View File

@ -2243,7 +2243,9 @@ function ensureSelectionExists(setting, selector) {
if (!selectElement) {
return;
}
if (selectElement.selectedOptions.length && !Array.from(selectElement.options).some(option => option.value === extension_settings.sd[setting])) {
const options = Array.from(selectElement.options);
const value = extension_settings.sd[setting];
if (selectElement.selectedOptions.length && !options.some(option => option.value === value)) {
extension_settings.sd[setting] = selectElement.selectedOptions[0].value;
}
}