fix: 搜索高亮跟随滚动同步 + 行号动态行高测量修复 v1.2.1

This commit is contained in:
thzxx
2026-05-27 17:34:30 +08:00
parent 8fea500cc1
commit eb05e9d1b1
5 changed files with 107 additions and 33 deletions
+6 -7
View File
@@ -195,16 +195,15 @@ function switchActiveFile(filePath) {
// IPC Handlers
// Save file to a specific path with watcher management
function saveToPath(filePath, content) {
async function saveToPath(filePath, content) {
stopWatching();
try {
isSelfWriting = true;
fs.writeFileSync(filePath, content, 'utf-8');
// 写入后短暂延迟再恢复监听,让 fs.watch 错过自身写入的事件
await fs.promises.writeFile(filePath, content, 'utf-8');
isSelfWriting = false;
} catch (err) {
isSelfWriting = false;
startWatching(activeFilePath); // Restore watcher on failure
startWatching(activeFilePath);
return { success: false, error: err.message };
}
activeFilePath = filePath;
@@ -250,7 +249,7 @@ ipcMain.handle('file:read', async (event, filePath) => {
ipcMain.handle('file:save', async (event, { filePath, content }) => {
try {
if (filePath) {
return saveToPath(filePath, content);
return await saveToPath(filePath, content);
} else {
const result = await dialog.showSaveDialog(mainWindow, {
filters: [
@@ -258,7 +257,7 @@ ipcMain.handle('file:save', async (event, { filePath, content }) => {
]
});
if (!result.canceled) {
return saveToPath(result.filePath, content);
return await saveToPath(result.filePath, content);
}
return { success: false, canceled: true };
}
@@ -275,7 +274,7 @@ ipcMain.handle('file:saveAs', async (event, { content }) => {
]
});
if (!result.canceled) {
return saveToPath(result.filePath, content);
return await saveToPath(result.filePath, content);
}
return { success: false, canceled: true };
} catch (err) {