From 79ebb044384fa487597a95f8d0c55137fb1b354a Mon Sep 17 00:00:00 2001 From: wzdnzd Date: Sat, 11 Mar 2023 09:42:34 +0800 Subject: [PATCH] reset selectedClashAPIConfigIndex when remove clashApiConfig --- src/store/app.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/store/app.ts b/src/store/app.ts index a3dde63..a9d0a52 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -55,6 +55,11 @@ export function removeClashAPIConfig(conf: ClashAPIConfig) { const idx = findClashAPIConfigIndex(getState, conf); dispatch('removeClashAPIConfig', (s) => { 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 saveState(getState().app);