diff --git a/newton/fs.js b/newton/fs.js index 1718c9c..472118f 100644 --- a/newton/fs.js +++ b/newton/fs.js @@ -12,7 +12,7 @@ const SETTINGS_CONFIG_PATH = path.join(CONFIG_PATH, "/settings.json"); const LSP_CONFIG_PATH = path.join(BASE_PATH, "/resources/lsp-servers-config.json"); let window = null; let watcher = null; -let skipWatchChangeUpdateOnce = false; +let skipOnceFileWatchChange = false; @@ -64,7 +64,7 @@ const saveSettingsConfigData = (data) => { } const saveFile = (fpath, content) => { - skipWatchChangeUpdateOnce = true; + skipOnceFileWatchChange = true; fs.writeFile(fpath, content, (err) => { if (err) { @@ -76,9 +76,9 @@ const saveFile = (fpath, content) => { let watchers = watcher.getWatched(); let targetDir = watchers[parentDir]; if ( - targetDir && !targetDir.includes( path.basename(fpath) ) + !targetDir || !targetDir.includes( path.basename(fpath) ) ) { - skipWatchChangeUpdateOnce = false; + skipOnceFileWatchChange = false; watcher.add(fpath); window.webContents.send('update-file-path', fpath); } @@ -143,13 +143,14 @@ const loadFilesWatcher = () => { watcher = chokidar.watch([], {}); watcher.on('change', (fpath) => { - if (skipWatchChangeUpdateOnce) { - skipWatchChangeUpdateOnce = false; + if (skipOnceFileWatchChange) { + skipOnceFileWatchChange = false; return; } console.debug("File (changed) : ", fpath); - window.webContents.send('file-changed', fpath); + const data = getFileContents(fpath, false, false); + window.webContents.send('file-changed', fpath, data); }).on('unlink', (fpath) => { console.debug("File (deleted) : ", fpath); window.webContents.send('file-deleted', fpath); diff --git a/newton/preload.js b/newton/preload.js index bb6b9b9..047a0ad 100644 --- a/newton/preload.js +++ b/newton/preload.js @@ -24,6 +24,6 @@ contextBridge.exposeInMainWorld('fs', { onLoadFiles: (callback) => ipcRenderer.on('load-files', (_event, paths) => callback(paths)), onUpdateFilePath: (callback) => ipcRenderer.on('update-file-path', (_event, paths) => callback(paths)), onSavedFile: (callback) => ipcRenderer.on('file-saved', (_event, path) => callback(path)), - onChangedFile: (callback) => ipcRenderer.on('file-changed', (_event, path) => callback(path)), + onChangedFile: (callback) => ipcRenderer.on('file-changed', (_event, path, data) => callback(path, data)), onDeletedFile: (callback) => ipcRenderer.on('file-deleted', (_event, path) => callback(path)), }); \ No newline at end of file diff --git a/src/app/editor/editors.component.ts b/src/app/editor/editors.component.ts index 92819f2..8844ea8 100644 --- a/src/app/editor/editors.component.ts +++ b/src/app/editor/editors.component.ts @@ -149,10 +149,15 @@ export class EditorsComponent { this.setSession(file); }); - window.fs.onChangedFile(async (path: string) => { + window.fs.onChangedFile(async (path: string, data: string) => { + let file = this.filesService.get(path); + file.session.setValue(data); + + // Note: fake 'save' event to not show as changed iven external save happened... let message = new ServiceMessage(); - message.action = "file-changed"; + message.action = "file-saved"; message.filePath = path; + this.tabsService.sendMessage(message); });