From 94ad99dc4d6b3fd21d612b5c04d79ac39838a428 Mon Sep 17 00:00:00 2001 From: Amit Haridas Date: Sun, 24 May 2026 23:54:31 +0530 Subject: [PATCH] fix(renderer): ensure tab content visibility after file open - Add missing updateUI() call at end of openFile() to set .active class on tab content. Without this, the CSS rule .tab-content:not(.active) { display: none } kept newly opened files invisible. - Add diagnostic logging to file-opened IPC handler and openFile() to trace future file loading issues. - Add diagnostic logging to openFileFromPath() in main process. Amit Haridas --- src/main.js | 3 ++- src/renderer.js | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index e44c884..9378356 100644 --- a/src/main.js +++ b/src/main.js @@ -3759,7 +3759,7 @@ app.on('open-file', (event, filePath) => { // Handle file opening from command line or file association function openFileFromPath(filePath) { console.log('[MAIN] openFileFromPath called with:', filePath); - console.log('[MAIN] rendererReady:', rendererReady, 'mainWindow exists:', !!mainWindow); + console.log('[MAIN] rendererReady:', rendererReady, 'mainWindow exists:', !!mainWindow, 'webContents exists:', !!(mainWindow?.webContents)); if (fs.existsSync(filePath)) { const stats = fs.statSync(filePath); if (stats.size > MAX_FILE_SIZE) { @@ -3769,6 +3769,7 @@ function openFileFromPath(filePath) { currentFile = filePath; const content = fs.readFileSync(filePath, 'utf-8'); console.log('[MAIN] File read successfully, content length:', content.length); + console.log('[MAIN] About to send file-opened. mainWindow:', !!mainWindow, 'webContents:', !!(mainWindow?.webContents), 'rendererReady:', rendererReady); if (mainWindow && mainWindow.webContents && rendererReady) { // Send file immediately - renderer-ready means UI is initialized console.log('[MAIN] Sending file-opened to renderer'); diff --git a/src/renderer.js b/src/renderer.js index bf69455..f54ef99 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -230,7 +230,7 @@ class TabManager { editorView: null, findMatches: [], currentMatchIndex: -1, - type: type, + type: type, // 'markdown' or 'pdf' // PDF-specific state pdfDoc: null, pdfCurrentPage: 1, @@ -243,6 +243,7 @@ class TabManager { this.switchToTab(newTabId); this.startAutoSave(); this.updateTabBar(); + console.log('createNewTab: tab created with type:', type); } createPdfTab(filePath) { @@ -1331,6 +1332,7 @@ class TabManager { openFile(filePath, content) { console.log('openFile called with:', filePath, 'content length:', content.length); let tab = this.tabs.get(this.activeTabId); + console.log('openFile tab state before:', { id: tab?.id, hasEditorView: !!tab?.editorView, contentLength: tab?.content?.length, filePath: tab?.filePath, isDirty: tab?.isDirty }); // Handle both forward and back slashes for cross-platform compatibility const fileName = filePath.split(/[\\/]/).pop(); @@ -1346,6 +1348,7 @@ class TabManager { // Update the editor and preview this.setEditorContent(this.activeTabId, content); + console.log('openFile after setEditorContent, tab state:', { id: tab.id, hasEditorView: !!tab.editorView, contentLength: tab.content.length }); this.updatePreview(this.activeTabId); this.updateWordCount(); } else { @@ -1353,6 +1356,7 @@ class TabManager { console.log('Creating new tab for file'); this.createNewTab(); tab = this.tabs.get(this.activeTabId); + console.log('openFile after createNewTab, tab:', { id: tab.id, hasEditorView: !!tab.editorView }); tab.filePath = filePath; tab.title = fileName; tab.content = content; @@ -1361,6 +1365,7 @@ class TabManager { // Set content in the CodeMirror editor this.setEditorContent(this.activeTabId, content); + console.log('openFile after setEditorContent, tab state:', { id: tab.id, hasEditorView: !!tab.editorView, contentLength: tab.content.length }); this.updatePreview(this.activeTabId); this.updateWordCount(); } @@ -1369,6 +1374,7 @@ class TabManager { this.updateTabBar(); this.updateFilePath(); this.updateBreadcrumb(); + this.updateUI(); // Ensure tab content is visible // Notify main process about current file for exports ipcRenderer.send('set-current-file', filePath); @@ -1835,6 +1841,7 @@ document.addEventListener('DOMContentLoaded', async () => { }, 30000); }); +// IPC event listeners // IPC event listeners ipcRenderer.on('file-new', () => { tabManager.createNewTab(); @@ -1842,8 +1849,20 @@ ipcRenderer.on('file-new', () => { ipcRenderer.on('file-opened', (event, data) => { console.log('[RENDERER] file-opened received:', data.path, 'content length:', data.content.length); + console.log('[RENDERER] activeTabId before openFile:', tabManager.activeTabId); + // Diagnostic: check library state + console.log('[RENDERER] Library state:', { + marked: typeof marked, + DOMPurify: typeof DOMPurify, + markedParse: typeof marked?.parse, + dompurifySanitize: typeof DOMPurify?.sanitize, + tabManagerExists: !!tabManager + }); if (tabManager) { tabManager.openFile(data.path, data.content); + console.log('[RENDERER] activeTabId after openFile:', tabManager.activeTabId); + const tab = tabManager.tabs.get(tabManager.activeTabId); + console.log('[RENDERER] tab state:', { id: tab?.id, hasEditorView: !!tab?.editorView, contentLength: tab?.content?.length }); } else { console.error('[RENDERER] tabManager not initialized!'); }