Skip to content

Commit b8c12e7

Browse files
committed
Bugfix: ESC during loading took to the wrong place
1 parent affa548 commit b8c12e7

2 files changed

Lines changed: 76 additions & 48 deletions

File tree

apps/desktop/src/lib/file-explorer/DualPaneExplorer.svelte

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -354,53 +354,72 @@
354354
return false
355355
}
356356
357-
// Handle cancel loading for left pane - navigate back in history or to home
358-
function handleLeftCancelLoading() {
359-
if (canGoBack(leftHistory)) {
360-
void handleNavigationAction('back')
357+
// Handle cancel loading for left pane - reload current history entry (the folder we were in before the slow load)
358+
// The slow-loading folder was never added to history, so current entry is already correct.
359+
function handleLeftCancelLoading(selectName?: string) {
360+
const entry = getCurrentEntry(leftHistory)
361+
362+
if (entry.volumeId === 'network') {
363+
leftPath = entry.path
364+
leftVolumeId = 'network'
365+
void saveAppStatus({ leftVolumeId: 'network', leftPath: entry.path })
366+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
367+
leftPaneRef?.setNetworkHost?.(entry.networkHost ?? null)
361368
} else {
362-
// Navigate to home
363-
leftPath = '~'
364-
leftVolumeId = DEFAULT_VOLUME_ID
365-
void saveAppStatus({ leftPath: '~', leftVolumeId: DEFAULT_VOLUME_ID })
366-
}
367-
}
368-
369-
// Handle cancel loading for right pane - navigate back in history or to home
370-
function handleRightCancelLoading() {
371-
if (canGoBack(rightHistory)) {
372-
// Need to handle this specially since handleNavigationAction uses focusedPane
373-
const history = rightHistory
374-
const newHistory = back(history)
375-
const targetEntry = getCurrentEntry(newHistory)
376-
377-
if (targetEntry.volumeId === 'network') {
378-
rightHistory = newHistory
379-
rightPath = targetEntry.path
380-
rightVolumeId = 'network'
381-
void saveAppStatus({ rightVolumeId: 'network', rightPath: targetEntry.path })
382-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
383-
rightPaneRef?.setNetworkHost?.(targetEntry.networkHost ?? null)
384-
} else {
385-
void resolveValidPath(targetEntry.path).then((resolvedPath) => {
386-
if (resolvedPath !== null) {
387-
rightHistory = newHistory
388-
rightPath = resolvedPath
389-
if (targetEntry.volumeId !== rightVolumeId) {
390-
rightVolumeId = targetEntry.volumeId
391-
void saveAppStatus({ rightVolumeId: targetEntry.volumeId, rightPath: resolvedPath })
392-
} else {
393-
void saveAppStatus({ rightPath: resolvedPath })
394-
}
395-
void saveLastUsedPathForVolume(targetEntry.volumeId, resolvedPath)
369+
void resolveValidPath(entry.path).then((resolvedPath) => {
370+
if (resolvedPath !== null) {
371+
leftPath = resolvedPath
372+
if (entry.volumeId !== leftVolumeId) {
373+
leftVolumeId = entry.volumeId
374+
void saveAppStatus({ leftVolumeId: entry.volumeId, leftPath: resolvedPath })
375+
} else {
376+
void saveAppStatus({ leftPath: resolvedPath })
396377
}
397-
})
398-
}
378+
// Navigate with selection to restore cursor to the folder we tried to enter
379+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
380+
leftPaneRef?.navigateToPath?.(resolvedPath, selectName)
381+
} else {
382+
// Path doesn't exist, fall back to home
383+
leftPath = '~'
384+
leftVolumeId = DEFAULT_VOLUME_ID
385+
void saveAppStatus({ leftPath: '~', leftVolumeId: DEFAULT_VOLUME_ID })
386+
}
387+
})
388+
}
389+
containerElement?.focus()
390+
}
391+
392+
// Handle cancel loading for right pane - reload current history entry (the folder we were in before the slow load)
393+
// The slow-loading folder was never added to history, so current entry is already correct.
394+
function handleRightCancelLoading(selectName?: string) {
395+
const entry = getCurrentEntry(rightHistory)
396+
397+
if (entry.volumeId === 'network') {
398+
rightPath = entry.path
399+
rightVolumeId = 'network'
400+
void saveAppStatus({ rightVolumeId: 'network', rightPath: entry.path })
401+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
402+
rightPaneRef?.setNetworkHost?.(entry.networkHost ?? null)
399403
} else {
400-
// Navigate to home
401-
rightPath = '~'
402-
rightVolumeId = DEFAULT_VOLUME_ID
403-
void saveAppStatus({ rightPath: '~', rightVolumeId: DEFAULT_VOLUME_ID })
404+
void resolveValidPath(entry.path).then((resolvedPath) => {
405+
if (resolvedPath !== null) {
406+
rightPath = resolvedPath
407+
if (entry.volumeId !== rightVolumeId) {
408+
rightVolumeId = entry.volumeId
409+
void saveAppStatus({ rightVolumeId: entry.volumeId, rightPath: resolvedPath })
410+
} else {
411+
void saveAppStatus({ rightPath: resolvedPath })
412+
}
413+
// Navigate with selection to restore cursor to the folder we tried to enter
414+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
415+
rightPaneRef?.navigateToPath?.(resolvedPath, selectName)
416+
} else {
417+
// Path doesn't exist, fall back to home
418+
rightPath = '~'
419+
rightVolumeId = DEFAULT_VOLUME_ID
420+
void saveAppStatus({ rightPath: '~', rightVolumeId: DEFAULT_VOLUME_ID })
421+
}
422+
})
404423
}
405424
containerElement?.focus()
406425
}

apps/desktop/src/lib/file-explorer/FilePane.svelte

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
onRequestFocus?: () => void
7373
/** Called when active network host changes (for history tracking) */
7474
onNetworkHostChange?: (host: NetworkHost | null) => void
75-
/** Called when user cancels loading (ESC key) - parent should navigate back */
76-
onCancelLoading?: () => void
75+
/** Called when user cancels loading (ESC key) - parent should reload previous folder, optionally selecting the folder we tried to enter */
76+
onCancelLoading?: (selectName?: string) => void
7777
}
7878
7979
const {
@@ -655,8 +655,17 @@
655655
// Cancel the Rust-side operation
656656
void cancelListing(listingId)
657657
658-
// Navigate back or to home via callback
659-
onCancelLoading?.()
658+
// Extract the folder name we were trying to enter, so parent can select it when reloading
659+
const folderName = currentPath.split('/').pop()
660+
661+
// Reload previous folder via callback (parent will set the path, triggering our effect)
662+
onCancelLoading?.(folderName)
663+
}
664+
665+
// Navigate to a specific path with optional item selection (used when cancelling navigation)
666+
export function navigateToPath(path: string, selectName?: string) {
667+
currentPath = path
668+
void loadDirectory(path, selectName)
660669
}
661670
662671
// Fetch the entry currently under the cursor for SelectionInfo

0 commit comments

Comments
 (0)