fix(tabs): update tab closing logic to handle dormant tabs

- Modified the `closeTab` function in the `useTabs` hook to reactivate dormant tabs when closed.
- Ensured that dormant tabs are marked as active and their state is updated upon reactivation, improving tab management and user experience.

These changes enhance the functionality of tab closing, providing a smoother interaction with dormant tabs.
This commit is contained in:
MyPrototypeWhat 2025-12-12 15:34:08 +08:00
parent bcbd5ed717
commit eec9048c11

View File

@ -197,13 +197,19 @@ export function useTabs() {
const closeTab = useCallback( const closeTab = useCallback(
(id: string) => { (id: string) => {
const newTabs = tabs.filter((t) => t.id !== id) let newTabs = tabs.filter((t) => t.id !== id)
let newActiveId = activeTabId let newActiveId = activeTabId
if (activeTabId === id) { if (activeTabId === id) {
const index = tabs.findIndex((t) => t.id === id) const index = tabs.findIndex((t) => t.id === id)
const nextTab = newTabs[index - 1] || newTabs[index] const nextTab = newTabs[index - 1] || newTabs[index]
newActiveId = nextTab ? nextTab.id : '' newActiveId = nextTab ? nextTab.id : ''
if (nextTab?.isDormant) {
newTabs = newTabs.map((t) =>
t.id === nextTab.id ? { ...t, isDormant: false, lastAccessTime: Date.now() } : t
)
}
} }
setTabsState({ tabs: newTabs, activeTabId: newActiveId }) setTabsState({ tabs: newTabs, activeTabId: newActiveId })