|
38 | 38 | } from '../types' |
39 | 39 | import { defaultSortOrders } from '../types' |
40 | 40 | import { ensureFontMetricsLoaded } from '$lib/font-metrics' |
41 | | - import { determineNavigationPath } from '../navigation/path-navigation' |
| 41 | + import { determineNavigationPath, resolveValidPath } from '../navigation/path-navigation' |
42 | 42 | import { |
43 | 43 | createHistory, |
44 | 44 | push, |
|
551 | 551 | containerElement?.focus() |
552 | 552 | } |
553 | 553 |
|
554 | | - function handleCancelLoading(pane: 'left' | 'right') { |
555 | | - const entry = getCurrentEntry(getPaneHistory(pane)) |
| 554 | + function handleCancelLoading(pane: 'left' | 'right', cancelledPath: string, selectName?: string) { |
| 555 | + const history = getPaneHistory(pane) |
| 556 | + const entry = getCurrentEntry(history) |
556 | 557 | const paneRef = getPaneRef(pane) |
557 | 558 |
|
558 | 559 | if (entry.volumeId === 'network') { |
|
561 | 562 | saveAppStatus({ [paneKey(pane, 'volumeId')]: 'network', [paneKey(pane, 'path')]: entry.path }) |
562 | 563 | // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
563 | 564 | paneRef?.setNetworkHost?.(entry.networkHost ?? null) |
564 | | - } else { |
565 | | - // Immediately navigate to a known-safe local path — the user pressed ESC, they want out |
566 | | - setPanePath(pane, '~') |
567 | | - setPaneVolumeId(pane, DEFAULT_VOLUME_ID) |
568 | | - saveAppStatus({ [paneKey(pane, 'path')]: '~', [paneKey(pane, 'volumeId')]: DEFAULT_VOLUME_ID }) |
| 565 | + saveTabsForPaneSide(pane) |
| 566 | + containerElement?.focus() |
| 567 | + return |
569 | 568 | } |
570 | | - saveTabsForPaneSide(pane) |
| 569 | +
|
| 570 | + if (entry.path === cancelledPath) { |
| 571 | + // Listing completed before cancel — history has the cancelled path pushed. Go back. |
| 572 | + if (canGoBack(history)) { |
| 573 | + const newHistory = back(history) |
| 574 | + const target = getCurrentEntry(newHistory) |
| 575 | + updatePaneAfterHistoryNavigation(pane, newHistory, target.path) |
| 576 | + return |
| 577 | + } |
| 578 | +
|
| 579 | + // Edge case: tab opened directly at this path, no history. Walk up to nearest valid parent. |
| 580 | + const parentPath = entry.path.substring(0, Math.max(1, entry.path.lastIndexOf('/'))) |
| 581 | + void resolveValidPath(parentPath).then((validPath) => { |
| 582 | + const target = validPath ?? '~' |
| 583 | + setPanePath(pane, target) |
| 584 | + saveAppStatus({ [paneKey(pane, 'path')]: target }) |
| 585 | + saveTabsForPaneSide(pane) |
| 586 | + containerElement?.focus() |
| 587 | + }) |
| 588 | + return |
| 589 | + } |
| 590 | +
|
| 591 | + // Listing didn't complete — history still points at the previous folder (correct destination). |
| 592 | + // setPanePath won't trigger FilePane's $effect (path unchanged), so call navigateToPath directly. |
| 593 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 594 | + paneRef?.navigateToPath?.(entry.path, selectName) |
571 | 595 | containerElement?.focus() |
572 | 596 | } |
573 | 597 |
|
|
1977 | 2001 | onNetworkHostChange={(host: NetworkHost | null) => { |
1978 | 2002 | handleNetworkHostChange(paneId, host) |
1979 | 2003 | }} |
1980 | | - onCancelLoading={() => { |
1981 | | - handleCancelLoading(paneId) |
| 2004 | + onCancelLoading={(cancelledPath: string, selectName?: string) => { |
| 2005 | + handleCancelLoading(paneId, cancelledPath, selectName) |
1982 | 2006 | }} |
1983 | 2007 | onMtpFatalError={(msg: string) => handleMtpFatalError(paneId, msg)} |
1984 | 2008 | /> |
|
0 commit comments