mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 10:00:17 +05:30
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
This commit is contained in:
+2
-1
@@ -3759,7 +3759,7 @@ app.on('open-file', (event, filePath) => {
|
|||||||
// Handle file opening from command line or file association
|
// Handle file opening from command line or file association
|
||||||
function openFileFromPath(filePath) {
|
function openFileFromPath(filePath) {
|
||||||
console.log('[MAIN] openFileFromPath called with:', 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)) {
|
if (fs.existsSync(filePath)) {
|
||||||
const stats = fs.statSync(filePath);
|
const stats = fs.statSync(filePath);
|
||||||
if (stats.size > MAX_FILE_SIZE) {
|
if (stats.size > MAX_FILE_SIZE) {
|
||||||
@@ -3769,6 +3769,7 @@ function openFileFromPath(filePath) {
|
|||||||
currentFile = filePath;
|
currentFile = filePath;
|
||||||
const content = fs.readFileSync(filePath, 'utf-8');
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
console.log('[MAIN] File read successfully, content length:', content.length);
|
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) {
|
if (mainWindow && mainWindow.webContents && rendererReady) {
|
||||||
// Send file immediately - renderer-ready means UI is initialized
|
// Send file immediately - renderer-ready means UI is initialized
|
||||||
console.log('[MAIN] Sending file-opened to renderer');
|
console.log('[MAIN] Sending file-opened to renderer');
|
||||||
|
|||||||
+20
-1
@@ -230,7 +230,7 @@ class TabManager {
|
|||||||
editorView: null,
|
editorView: null,
|
||||||
findMatches: [],
|
findMatches: [],
|
||||||
currentMatchIndex: -1,
|
currentMatchIndex: -1,
|
||||||
type: type,
|
type: type, // 'markdown' or 'pdf'
|
||||||
// PDF-specific state
|
// PDF-specific state
|
||||||
pdfDoc: null,
|
pdfDoc: null,
|
||||||
pdfCurrentPage: 1,
|
pdfCurrentPage: 1,
|
||||||
@@ -243,6 +243,7 @@ class TabManager {
|
|||||||
this.switchToTab(newTabId);
|
this.switchToTab(newTabId);
|
||||||
this.startAutoSave();
|
this.startAutoSave();
|
||||||
this.updateTabBar();
|
this.updateTabBar();
|
||||||
|
console.log('createNewTab: tab created with type:', type);
|
||||||
}
|
}
|
||||||
|
|
||||||
createPdfTab(filePath) {
|
createPdfTab(filePath) {
|
||||||
@@ -1331,6 +1332,7 @@ class TabManager {
|
|||||||
openFile(filePath, content) {
|
openFile(filePath, content) {
|
||||||
console.log('openFile called with:', filePath, 'content length:', content.length);
|
console.log('openFile called with:', filePath, 'content length:', content.length);
|
||||||
let tab = this.tabs.get(this.activeTabId);
|
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
|
// Handle both forward and back slashes for cross-platform compatibility
|
||||||
const fileName = filePath.split(/[\\/]/).pop();
|
const fileName = filePath.split(/[\\/]/).pop();
|
||||||
@@ -1346,6 +1348,7 @@ class TabManager {
|
|||||||
|
|
||||||
// Update the editor and preview
|
// Update the editor and preview
|
||||||
this.setEditorContent(this.activeTabId, content);
|
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.updatePreview(this.activeTabId);
|
||||||
this.updateWordCount();
|
this.updateWordCount();
|
||||||
} else {
|
} else {
|
||||||
@@ -1353,6 +1356,7 @@ class TabManager {
|
|||||||
console.log('Creating new tab for file');
|
console.log('Creating new tab for file');
|
||||||
this.createNewTab();
|
this.createNewTab();
|
||||||
tab = this.tabs.get(this.activeTabId);
|
tab = this.tabs.get(this.activeTabId);
|
||||||
|
console.log('openFile after createNewTab, tab:', { id: tab.id, hasEditorView: !!tab.editorView });
|
||||||
tab.filePath = filePath;
|
tab.filePath = filePath;
|
||||||
tab.title = fileName;
|
tab.title = fileName;
|
||||||
tab.content = content;
|
tab.content = content;
|
||||||
@@ -1361,6 +1365,7 @@ class TabManager {
|
|||||||
|
|
||||||
// Set content in the CodeMirror editor
|
// Set content in the CodeMirror editor
|
||||||
this.setEditorContent(this.activeTabId, content);
|
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.updatePreview(this.activeTabId);
|
||||||
this.updateWordCount();
|
this.updateWordCount();
|
||||||
}
|
}
|
||||||
@@ -1369,6 +1374,7 @@ class TabManager {
|
|||||||
this.updateTabBar();
|
this.updateTabBar();
|
||||||
this.updateFilePath();
|
this.updateFilePath();
|
||||||
this.updateBreadcrumb();
|
this.updateBreadcrumb();
|
||||||
|
this.updateUI(); // Ensure tab content is visible
|
||||||
|
|
||||||
// Notify main process about current file for exports
|
// Notify main process about current file for exports
|
||||||
ipcRenderer.send('set-current-file', filePath);
|
ipcRenderer.send('set-current-file', filePath);
|
||||||
@@ -1835,6 +1841,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
}, 30000);
|
}, 30000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// IPC event listeners
|
||||||
// IPC event listeners
|
// IPC event listeners
|
||||||
ipcRenderer.on('file-new', () => {
|
ipcRenderer.on('file-new', () => {
|
||||||
tabManager.createNewTab();
|
tabManager.createNewTab();
|
||||||
@@ -1842,8 +1849,20 @@ ipcRenderer.on('file-new', () => {
|
|||||||
|
|
||||||
ipcRenderer.on('file-opened', (event, data) => {
|
ipcRenderer.on('file-opened', (event, data) => {
|
||||||
console.log('[RENDERER] file-opened received:', data.path, 'content length:', data.content.length);
|
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) {
|
if (tabManager) {
|
||||||
tabManager.openFile(data.path, data.content);
|
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 {
|
} else {
|
||||||
console.error('[RENDERER] tabManager not initialized!');
|
console.error('[RENDERER] tabManager not initialized!');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user