清理:移除未使用的 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, {
|
const result = await dialog.showOpenDialog(mainWindow, {
|
||||||
properties: multi ? ['openFile', 'multiSelections'] : ['openFile'],
|
properties: ['openFile'],
|
||||||
filters: [
|
filters: [
|
||||||
{ name: 'Markdown 文件', extensions: ['md', 'markdown', 'txt'] },
|
{ name: 'Markdown 文件', extensions: ['md', 'markdown', 'txt'] },
|
||||||
{ name: '所有文件', extensions: ['*'] }
|
{ name: '所有文件', extensions: ['*'] }
|
||||||
@@ -131,7 +131,7 @@ function switchActiveFile(filePath) {
|
|||||||
// Open single file via dialog
|
// Open single file via dialog
|
||||||
ipcMain.handle('dialog:openFile', async () => {
|
ipcMain.handle('dialog:openFile', async () => {
|
||||||
try {
|
try {
|
||||||
const files = await showOpenDialog(false);
|
const files = await showOpenDialog();
|
||||||
if (files && files.length > 0) {
|
if (files && files.length > 0) {
|
||||||
const content = readFileContent(files[0]);
|
const content = readFileContent(files[0]);
|
||||||
activeFilePath = 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) => {
|
ipcMain.handle('file:read', async (event, filePath) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const { contextBridge, ipcRenderer } = require('electron');
|
|||||||
contextBridge.exposeInMainWorld('electronAPI', {
|
contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
// File operations
|
// File operations
|
||||||
openFile: () => ipcRenderer.invoke('dialog:openFile'),
|
openFile: () => ipcRenderer.invoke('dialog:openFile'),
|
||||||
openFiles: () => ipcRenderer.invoke('dialog:openFiles'),
|
|
||||||
readFile: (filePath) => ipcRenderer.invoke('file:read', filePath),
|
readFile: (filePath) => ipcRenderer.invoke('file:read', filePath),
|
||||||
saveFile: (data) => ipcRenderer.invoke('file:save', data),
|
saveFile: (data) => ipcRenderer.invoke('file:save', data),
|
||||||
saveFileAs: (data) => ipcRenderer.invoke('file:saveAs', data),
|
saveFileAs: (data) => ipcRenderer.invoke('file:saveAs', data),
|
||||||
|
|||||||
@@ -297,7 +297,9 @@
|
|||||||
const tab = getActiveTab();
|
const tab = getActiveTab();
|
||||||
if (tab) {
|
if (tab) {
|
||||||
tab.isModified = modified;
|
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();
|
updateTitle();
|
||||||
}
|
}
|
||||||
@@ -672,8 +674,7 @@
|
|||||||
if (tab) {
|
if (tab) {
|
||||||
tab.isModified = true;
|
tab.isModified = true;
|
||||||
tab.content = editor.value;
|
tab.content = editor.value;
|
||||||
renderTabBar();
|
setModified(true);
|
||||||
updateTitle();
|
|
||||||
}
|
}
|
||||||
scheduleUpdate();
|
scheduleUpdate();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user