reset selectedClashAPIConfigIndex when remove clashApiConfig

This commit is contained in:
wzdnzd 2023-03-11 09:42:34 +08:00
parent e7a5088b97
commit 79ebb04438

View file

@ -55,6 +55,11 @@ export function removeClashAPIConfig(conf: ClashAPIConfig) {
const idx = findClashAPIConfigIndex(getState, conf); const idx = findClashAPIConfigIndex(getState, conf);
dispatch('removeClashAPIConfig', (s) => { dispatch('removeClashAPIConfig', (s) => {
s.app.clashAPIConfigs.splice(idx, 1); s.app.clashAPIConfigs.splice(idx, 1);
if (idx === s.app.selectedClashAPIConfigIndex) {
s.app.selectedClashAPIConfigIndex = 0;
} else if (idx < s.app.selectedClashAPIConfigIndex) {
s.app.selectedClashAPIConfigIndex -= 1;
}
}); });
// side effect // side effect
saveState(getState().app); saveState(getState().app);