Skip to content

Commit ede4d93

Browse files
committed
fix: tabs: restoring tree state from session data in some failure cases
This and 05aedbb, d21f816, 5979d7a, a2c6a59, c83df0b, 0d585f0 should fix or at least decrease probability of problems related with broken tabs structure on init (like #1507, #262, #267, and so on...)
1 parent b0c1c38 commit ede4d93

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/services/tabs.fg.actions.ts

+23-21
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ function restoreTabsFromCache(
363363
): Tab[] {
364364
Logs.info('Tabs.restoreTabsFromCache')
365365

366-
let logWrongPanels: Record<string, null> | undefined
367366
const firstPanelId = lastPanel.id
368367
const idsMap: Record<ID, ID> = {}
369368
const tabs: Tab[] = []
@@ -393,8 +392,6 @@ function restoreTabsFromCache(
393392
// Normalize panelId
394393
const panel = Sidebar.panelsById[tab.panelId]
395394
if (!panel) {
396-
if (!logWrongPanels) logWrongPanels = {}
397-
logWrongPanels[tab.panelId] = null
398395
tab.panelId = lastPanel.id
399396
} else {
400397
if (!tab.pinned) {
@@ -414,10 +411,6 @@ function restoreTabsFromCache(
414411
tabs.push(tab)
415412
}
416413

417-
if (logWrongPanels) {
418-
Logs.warn('Tabs loading: Cannot find panels: ' + Object.keys(logWrongPanels).join(' '))
419-
}
420-
421414
return tabs
422415
}
423416

@@ -428,7 +421,6 @@ function restoreTabsFromSessionData(
428421
): Tab[] {
429422
Logs.info('Tabs.restoreTabsFromSessionData')
430423

431-
let logWrongPanels: Record<string, null> | undefined
432424
const firstPanelId = lastPanel.id
433425
const idsMap: Record<ID, ID> = {}
434426
const tabs: Tab[] = []
@@ -462,17 +454,7 @@ function restoreTabsFromSessionData(
462454

463455
// Normalize panelId
464456
const panel = Sidebar.panelsById[tab.panelId]
465-
if (!panel) {
466-
if (!logWrongPanels) logWrongPanels = {}
467-
logWrongPanels[tab.panelId] = null
468-
tab.panelId = lastPanel.id
469-
} else {
470-
if (!tab.pinned) {
471-
// Check order of panels
472-
if (panel.index < lastPanel.index) tab.panelId = lastPanel.id
473-
else lastPanel = panel
474-
}
475-
}
457+
if (!panel) tab.panelId = lastPanel.id
476458

477459
// Use openerTabId as fallback for parentId
478460
if (tab.parentId === -1 && tab.openerTabId !== undefined && Tabs.byId[tab.openerTabId]) {
@@ -484,8 +466,28 @@ function restoreTabsFromSessionData(
484466
tabs.push(tab)
485467
}
486468

487-
if (logWrongPanels) {
488-
Logs.warn('Tabs loading: Cannot find panels: ' + Object.keys(logWrongPanels).join(' '))
469+
let lastPanelIndex = -1
470+
for (const panel of Sidebar.panels) {
471+
if (!Utils.isTabsPanel(panel)) continue
472+
473+
let prevTabIndex = -1
474+
for (let ti = 0; ti < tabs.length; ti++) {
475+
const tab = tabs[ti]
476+
if (tab.pinned) continue
477+
478+
if (tab.panelId !== panel.id) continue
479+
480+
if (tab.index <= lastPanelIndex || (prevTabIndex !== -1 && tab.index - 1 !== prevTabIndex)) {
481+
let prevTab = tabs[ti - 1] as Tab | undefined
482+
if (prevTab?.pinned) prevTab = undefined
483+
tab.panelId = prevTab?.panelId ?? firstPanelId
484+
continue
485+
}
486+
487+
prevTabIndex = tab.index
488+
}
489+
490+
lastPanelIndex = prevTabIndex
489491
}
490492

491493
return tabs

0 commit comments

Comments
 (0)