fix: refresh dirty state after rename so indicator reflects reality
Two bugs caused stale dirty indicators after rename: 1. handleRenameTab didn't call loadModifiedFiles() after rename 2. handleSave (Cmd+S) skipped onAfterSave when nothing was pending Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -165,9 +165,8 @@ function App() {
|
||||
}, [notes])
|
||||
|
||||
const handleRenameTab = useCallback(async (path: string, newTitle: string) => {
|
||||
// Save any pending content before renaming so the file on disk is up to date
|
||||
await savePendingForPath(path)
|
||||
notes.handleRenameNote(path, newTitle, vaultPath, vault.replaceEntry)
|
||||
await notes.handleRenameNote(path, newTitle, vaultPath, vault.replaceEntry).then(vault.loadModifiedFiles)
|
||||
}, [notes, vaultPath, vault, savePendingForPath])
|
||||
|
||||
const { setViewMode } = useViewMode()
|
||||
|
||||
@@ -124,6 +124,21 @@ describe('useEditorSave', () => {
|
||||
expect(onAfterSave).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('calls onAfterSave even when nothing is pending (e.g. after rename)', async () => {
|
||||
const onAfterSave = vi.fn()
|
||||
const { result } = renderHook(() =>
|
||||
useEditorSave({ updateVaultContent, setTabs, setToastMessage, onAfterSave })
|
||||
)
|
||||
|
||||
// No content buffered — simulate Cmd+S after a rename that already flushed pending
|
||||
await act(async () => {
|
||||
await result.current.handleSave()
|
||||
})
|
||||
|
||||
expect(setToastMessage).toHaveBeenCalledWith('Nothing to save')
|
||||
expect(onAfterSave).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('does not call onAfterSave when save fails', async () => {
|
||||
mockInvokeFn.mockRejectedValueOnce(new Error('Disk full'))
|
||||
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
|
||||
@@ -45,8 +45,7 @@ export function useEditorSave({ updateVaultContent, setTabs, setToastMessage, on
|
||||
const handleSave = useCallback(async () => {
|
||||
try {
|
||||
const saved = await flushPending()
|
||||
if (!saved) { setToastMessage('Nothing to save'); return }
|
||||
setToastMessage('Saved')
|
||||
setToastMessage(saved ? 'Saved' : 'Nothing to save')
|
||||
onAfterSave?.()
|
||||
} catch (err) {
|
||||
console.error('Save failed:', err)
|
||||
|
||||
Reference in New Issue
Block a user