diff --git a/src/renderer/src/components/editor/EditorPanelHeaderPath.test.tsx b/src/renderer/src/components/editor/EditorPanelHeaderPath.test.tsx index 2c5cbe5f288..973ae4277d0 100644 --- a/src/renderer/src/components/editor/EditorPanelHeaderPath.test.tsx +++ b/src/renderer/src/components/editor/EditorPanelHeaderPath.test.tsx @@ -196,7 +196,8 @@ describe('EditorPanelHeaderPath inline rename', () => { const rerenderPath = renderPath(baseFile()) openRenameInput() - fireEvent.change(getRenameInput('Rename file notes.md'), { target: { value: 'renamed.md' } }) + const input = getRenameInput('Rename file notes.md') + fireEvent.change(input, { target: { value: 'renamed.md' } }) rerenderPath( baseFile({ id: '/repo/other.md', @@ -207,6 +208,9 @@ describe('EditorPanelHeaderPath inline rename', () => { expect(screen.queryByLabelText('Rename file notes.md')).toBeNull() expect(screen.queryByLabelText('Rename file other.md')).toBeNull() + + // React may deliver the removed input's blur after the active file render. + fireEvent.blur(input) expect(renameFileOnDiskMock).not.toHaveBeenCalled() }) diff --git a/src/renderer/src/components/editor/editor-header-file-rename.ts b/src/renderer/src/components/editor/editor-header-file-rename.ts index 328e2ba2c05..5dc67d80358 100644 --- a/src/renderer/src/components/editor/editor-header-file-rename.ts +++ b/src/renderer/src/components/editor/editor-header-file-rename.ts @@ -30,6 +30,7 @@ export function useEditorHeaderFileRename(activeFile: OpenFile): EditorHeaderFil // Why: the header renders one unkeyed path strip for every file, so a file // switch mid-rename would otherwise commit the typed name against the new path. if (renameFilePath !== activeFile.filePath) { + renameCancelledRef.current = true setRenameFilePath(activeFile.filePath) setIsRenaming(false) }