Skip to content

Commit e80b42a

Browse files
committed
refactor(Settings): streamline mod selection logic in RitsuModSettingsSubmenu
- Moved the call to ExpandOnlyMod into the conditional block to avoid redundant execution when selecting a mod. - Enhanced the logic for handling mod expansion and selection, ensuring UI updates are triggered only when necessary, improving performance and user experience.
1 parent 0918ac9 commit e80b42a

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

Settings/ModSettingsUi/Core/RitsuModSettingsSubmenu.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,10 +1221,9 @@ private void EnsureSelectionIsValid()
12211221
{
12221222
_selectedModId = rootPages[0].Key;
12231223
_selectionDirty = true;
1224+
ExpandOnlyMod(_selectedModId);
12241225
}
12251226

1226-
ExpandOnlyMod(_selectedModId);
1227-
12281227
var modPages = ModSettingsRegistry.GetPages()
12291228
.Where(page => string.Equals(page.ModId, _selectedModId, StringComparison.OrdinalIgnoreCase))
12301229
.OrderBy(ModSettingsRegistry.GetEffectivePageSortOrder)
@@ -1803,18 +1802,30 @@ private SidebarModCache CreateSidebarModCache(string modId)
18031802
string.Empty,
18041803
() =>
18051804
{
1806-
_selectedModId = modId;
1807-
_selectedPageId = ModSettingsRegistry.GetPages()
1808-
.Where(page => string.Equals(page.ModId, modId, StringComparison.OrdinalIgnoreCase) &&
1809-
string.IsNullOrWhiteSpace(page.ParentPageId))
1810-
.OrderBy(ModSettingsRegistry.GetEffectivePageSortOrder)
1811-
.ThenBy(page => page.Id, StringComparer.OrdinalIgnoreCase)
1812-
.Select(page => page.Id)
1813-
.FirstOrDefault();
1814-
_selectedSectionId = null;
1805+
if (_expandedModIds.Contains(modId))
1806+
{
1807+
_expandedModIds.Remove(modId);
1808+
_selectionDirty = true;
1809+
EnsureUiUpToDate();
1810+
return;
1811+
}
1812+
1813+
if (!string.Equals(_selectedModId, modId, StringComparison.OrdinalIgnoreCase))
1814+
{
1815+
_selectedModId = modId;
1816+
_selectedPageId = ModSettingsRegistry.GetPages()
1817+
.Where(page => string.Equals(page.ModId, modId, StringComparison.OrdinalIgnoreCase) &&
1818+
string.IsNullOrWhiteSpace(page.ParentPageId))
1819+
.OrderBy(ModSettingsRegistry.GetEffectivePageSortOrder)
1820+
.ThenBy(page => page.Id, StringComparer.OrdinalIgnoreCase)
1821+
.Select(page => page.Id)
1822+
.FirstOrDefault();
1823+
_selectedSectionId = null;
1824+
_focusSelectedPageButtonOnNextRefresh = true;
1825+
}
1826+
18151827
ExpandOnlyMod(modId);
18161828
_selectionDirty = true;
1817-
_focusSelectedPageButtonOnNextRefresh = true;
18181829
EnsureUiUpToDate();
18191830
},
18201831
ModSettingsSidebarItemKind.ModGroup,

0 commit comments

Comments
 (0)