diff --git a/frontend/js/pane-manager.js b/frontend/js/pane-manager.js index a7de1c8..0be3343 100644 --- a/frontend/js/pane-manager.js +++ b/frontend/js/pane-manager.js @@ -156,6 +156,12 @@ function createPaneTabManager(paneId) { this._dirtyTabs.delete(tabId); if (this._tabs.length === 0) { this._activeTabId = null; + // If this pane has no more tabs and isn't the last pane, close it + if (window.PaneManager && window.PaneManager.isSplit() && window.PaneManager.panes.length > 1) { + this._renderTabs(); + window.PaneManager.closePane(this.paneId); + return; + } this._showDashboard(); if (this._tabBar) this._tabBar.hidden = true; } else if (this._activeTabId === tabId) { @@ -216,9 +222,14 @@ function createPaneTabManager(paneId) { // Add to target targetTm._tabs.push({ ...tab, preview: false }); targetTm._tabCache[tabId] = cache || { vault: tab.vault, path: tab.path, title: tab.name, data: null, rawSource: null, sourceView: false, scrollTop: 0, icon: tab.icon }; - // Activate in source what's left, or show dashboard + // If source is now empty and not the last pane, close it if (this._tabs.length === 0) { this._activeTabId = null; + if (window.PaneManager && window.PaneManager.isSplit() && window.PaneManager.panes.length > 1) { + this._renderTabs(); + window.PaneManager.closePane(this.paneId); + return true; + } this._showDashboard(); if (this._tabBar) this._tabBar.hidden = true; } else if (this._activeTabId === tabId) { @@ -236,15 +247,13 @@ function createPaneTabManager(paneId) { // Set temporary override so getContentArea() returns this pane's area const prev = window._activePaneContentArea; window._activePaneContentArea = area; - try { - // Dynamic import to avoid circular dep — renderFile is in viewer.js - import('./viewer.js').then(m => { - m.renderFile(data); - window._activePaneContentArea = prev; - }); - } catch (e) { + // Use dynamic import to call viewer.js renderFile in the right context + import('./viewer.js').then(m => { + m.renderFile(data); window._activePaneContentArea = prev; - } + }).catch(() => { + window._activePaneContentArea = prev; + }); }, _saveCurrentTabState() { @@ -910,9 +919,9 @@ if (typeof window !== 'undefined') { }); // Init — wait for DOM + singleton TabManager to be ready setTimeout(() => { - // Store singleton TabManager reference - if (typeof TabManager !== 'undefined') - window._singletonTabManager = TabManager; + // Use window.TabManager (set by ui.js init) as the singleton fallback + if (!window._singletonTabManager && window.TabManager) + window._singletonTabManager = window.TabManager; PaneManager.init(); }, 150); }); diff --git a/frontend/js/ui.js b/frontend/js/ui.js index b30262f..bd3ba34 100644 --- a/frontend/js/ui.js +++ b/frontend/js/ui.js @@ -1880,6 +1880,9 @@ export const TabManager = { init() { this._tabBar = document.getElementById("tab-bar"); this._tabList = document.getElementById("tab-list"); + // Expose on window so pane-manager.js can reference the singleton + window.TabManager = this; + window._singletonTabManager = this; }, /** Open a file as a preview tab (single-click).