( history: TabHistoryEntry[], startIndex: number, direction: 1 | -1, tabs: Tab[], openTab: (tab: Tab, preview?: boolean) => void )
| 84 | } |
| 85 | |
| 86 | function tryNavigateToHistory( |
| 87 | history: TabHistoryEntry[], |
| 88 | startIndex: number, |
| 89 | direction: 1 | -1, |
| 90 | tabs: Tab[], |
| 91 | openTab: (tab: Tab, preview?: boolean) => void |
| 92 | ): { targetIndex: number; targetTabId: string } | null { |
| 93 | for (let i = startIndex; direction === -1 ? i >= 0 : i < history.length; i += direction) { |
| 94 | const entry = history[i] |
| 95 | |
| 96 | if (tabs.some((t) => t.id === entry.tabId)) { |
| 97 | return { targetIndex: i, targetTabId: entry.tabId } |
| 98 | } |
| 99 | |
| 100 | const restoredTab = tryRestoreTab(entry.type, entry.dataId) |
| 101 | if (restoredTab) { |
| 102 | isNavigating = true |
| 103 | try { |
| 104 | openTab({ ...restoredTab, preview: true }, true) |
| 105 | } finally { |
| 106 | isNavigating = false |
| 107 | } |
| 108 | return { targetIndex: i, targetTabId: restoredTab.id } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return null |
| 113 | } |
| 114 | |
| 115 | const persist = (state: TabsState): void => { |
| 116 | const scope = tryGetCurrentWorkspaceScope() |
no test coverage detected