From 5ff89edd2ba265831b7f0be35fe9880df6575b76 Mon Sep 17 00:00:00 2001 From: thzxx Date: Mon, 18 May 2026 13:31:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=EF=BC=9A=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84=20openFiles=20IPC=E3=80=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20setModified=20=E9=81=BF=E5=85=8D=E6=AF=8F?= =?UTF-8?q?=E6=AC=A1=E6=8C=89=E9=94=AE=E9=87=8D=E5=BB=BA=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=20DOM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 27 +++------------------------ preload.js | 1 - renderer/renderer.js | 7 ++++--- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/main.js b/main.js index 52dce35..be421d0 100644 --- a/main.js +++ b/main.js @@ -84,9 +84,9 @@ function stopWatching() { } } -async function showOpenDialog(multi) { +async function showOpenDialog() { const result = await dialog.showOpenDialog(mainWindow, { - properties: multi ? ['openFile', 'multiSelections'] : ['openFile'], + properties: ['openFile'], filters: [ { name: 'Markdown 文件', extensions: ['md', 'markdown', 'txt'] }, { name: '所有文件', extensions: ['*'] } @@ -131,7 +131,7 @@ function switchActiveFile(filePath) { // Open single file via dialog ipcMain.handle('dialog:openFile', async () => { try { - const files = await showOpenDialog(false); + const files = await showOpenDialog(); if (files && files.length > 0) { const content = readFileContent(files[0]); activeFilePath = files[0]; @@ -145,27 +145,6 @@ ipcMain.handle('dialog:openFile', async () => { } }); -// Open multiple files via dialog -ipcMain.handle('dialog:openFiles', async () => { - try { - const files = await showOpenDialog(true); - if (files && files.length > 0) { - const results = []; - for (const fp of files) { - try { - const content = readFileContent(fp); - results.push({ filePath: fp, content }); - } catch (err) { - results.push({ filePath: fp, error: err.message }); - } - } - return results; - } - return null; - } catch (err) { - return { error: err.message }; - } -}); ipcMain.handle('file:read', async (event, filePath) => { try { diff --git a/preload.js b/preload.js index f16d805..8258c3a 100644 --- a/preload.js +++ b/preload.js @@ -3,7 +3,6 @@ const { contextBridge, ipcRenderer } = require('electron'); contextBridge.exposeInMainWorld('electronAPI', { // File operations openFile: () => ipcRenderer.invoke('dialog:openFile'), - openFiles: () => ipcRenderer.invoke('dialog:openFiles'), readFile: (filePath) => ipcRenderer.invoke('file:read', filePath), saveFile: (data) => ipcRenderer.invoke('file:save', data), saveFileAs: (data) => ipcRenderer.invoke('file:saveAs', data), diff --git a/renderer/renderer.js b/renderer/renderer.js index 26739a8..8b59295 100644 --- a/renderer/renderer.js +++ b/renderer/renderer.js @@ -297,7 +297,9 @@ const tab = getActiveTab(); if (tab) { tab.isModified = modified; - renderTabBar(); + // Toggle class directly instead of rebuilding entire tab bar + const tabEl = tabList.querySelector(`.tab-item[data-tab-id="${tab.id}"]`); + if (tabEl) tabEl.classList.toggle('modified', modified); } updateTitle(); } @@ -672,8 +674,7 @@ if (tab) { tab.isModified = true; tab.content = editor.value; - renderTabBar(); - updateTitle(); + setModified(true); } scheduleUpdate(); });