清理:移除未使用的 openFiles IPC、优化 setModified 避免每次按键重建标签 DOM
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user