Skip to content

Commit eff84d1

Browse files
committed
Jump on new dir with the cursor after creating it
1 parent 2d7904f commit eff84d1

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

apps/desktop/src/lib/file-operations/mkdir/new-folder-operations.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,27 @@ export async function moveCursorToNewFolder(
3838
listen: ListenFn,
3939
findFileIndex: FindFileIndexFn,
4040
): Promise<void> {
41+
// Try to find the folder immediately — the directory-diff event often fires
42+
// before this listener is set up (the folder is created before onCreated runs).
43+
const tryMoveCursor = async (): Promise<boolean> => {
44+
const index = await findFileIndex(paneListingId, folderName, showHiddenFiles)
45+
if (index !== null) {
46+
const frontendIndex = hasParent ? index + 1 : index
47+
void paneRef?.setCursorIndex(frontendIndex)
48+
return true
49+
}
50+
return false
51+
}
52+
53+
// First attempt: folder may already be in the listing
54+
if (await tryMoveCursor()) return
55+
56+
// Fallback: wait for directory-diff in case the listing hasn't updated yet
4157
const unlisten = await listen('directory-diff', (event) => {
4258
if (event.payload.listingId !== paneListingId) return
43-
// Small delay to ensure listing cache is fully updated before querying
4459
setTimeout(() => {
45-
void findFileIndex(paneListingId, folderName, showHiddenFiles).then((index) => {
46-
if (index !== null) {
47-
const frontendIndex = hasParent ? index + 1 : index
48-
void paneRef?.setCursorIndex(frontendIndex)
49-
unlisten()
50-
}
60+
void tryMoveCursor().then((found) => {
61+
if (found) unlisten()
5162
})
5263
}, 50)
5364
})

0 commit comments

Comments
 (0)