fix: preserve editor focus during active note refresh

This commit is contained in:
lucaronin
2026-05-23 21:53:21 +02:00
parent 1c8207eeb5
commit ce237039c9
2 changed files with 60 additions and 8 deletions

View File

@@ -92,17 +92,29 @@ describe('refreshPulledVaultState', () => {
expect(options.closeAllTabs).not.toHaveBeenCalled()
})
it('refreshes the focused active tab when an external watcher update changed that note', async () => {
it('keeps the active tab mounted while focused when an external watcher update changed that note', async () => {
const options = makeOptions({
shouldKeepActiveEditorMounted: vi.fn(() => true),
})
await refreshPulledVaultState(options)
expect(options.shouldKeepActiveEditorMounted).not.toHaveBeenCalled()
expect(options.shouldKeepActiveEditorMounted).toHaveBeenCalledOnce()
expect(options.reloadVault).toHaveBeenCalledOnce()
expect(options.reloadFolders).toHaveBeenCalledOnce()
expect(options.reloadViews).toHaveBeenCalledOnce()
expect(options.closeAllTabs).not.toHaveBeenCalled()
expect(options.replaceActiveTab).not.toHaveBeenCalled()
})
it('refreshes the active tab when focus is outside the editor', async () => {
const options = makeOptions({
shouldKeepActiveEditorMounted: vi.fn(() => false),
})
await refreshPulledVaultState(options)
expect(options.shouldKeepActiveEditorMounted).toHaveBeenCalledOnce()
expect(options.closeAllTabs).toHaveBeenCalledOnce()
expect(options.replaceActiveTab).toHaveBeenCalledWith(makeEntry('/vault/active.md', 'Active'))
})