mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-29 18:36:23 +02:00
Enhance workspace change handling to reload current file on external changes, ensuring no unsaved edits are lost.
This commit is contained in:
parent
7387d3c1c9
commit
2f1131c57f
1 changed files with 21 additions and 2 deletions
|
|
@ -307,11 +307,30 @@ function App() {
|
|||
|
||||
// Listen to workspace change events
|
||||
useEffect(() => {
|
||||
const cleanup = window.ipc.on('workspace:didChange', () => {
|
||||
const cleanup = window.ipc.on('workspace:didChange', async (event) => {
|
||||
loadDirectory().then(setTree)
|
||||
|
||||
// Reload current file if it was changed externally
|
||||
if (!selectedPath) return
|
||||
|
||||
const changedPath = event.type === 'changed' ? event.path : null
|
||||
const changedPaths = (event.type === 'bulkChanged' ? event.paths : []) ?? []
|
||||
|
||||
const isCurrentFileChanged =
|
||||
changedPath === selectedPath || changedPaths.includes(selectedPath)
|
||||
|
||||
if (isCurrentFileChanged) {
|
||||
// Only reload if no unsaved edits
|
||||
if (editorContent === initialContentRef.current) {
|
||||
const result = await window.ipc.invoke('workspace:readFile', { path: selectedPath })
|
||||
setFileContent(result.data)
|
||||
setEditorContent(result.data)
|
||||
initialContentRef.current = result.data
|
||||
}
|
||||
}
|
||||
})
|
||||
return cleanup
|
||||
}, [loadDirectory])
|
||||
}, [loadDirectory, selectedPath, editorContent])
|
||||
|
||||
// Load file content when selected
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue