fix(ui): leave the file manager after a drive hop instead of replaying hops (#2567)

Back replays the history stack, so a round trip between drives leaves one
entry per hop: internal storage, Linux, internal storage, then Back lands
on Linux again and leaving takes one press per hop. Two roots in a row
means the user hopped rather than descended into a folder, so Back leaves
instead. Returning to a folder from a drive root still works as before.

Co-authored-by: Dantalian <Dantalian-dev@users.noreply.github.com>
This commit is contained in:
DantalianandDantalian authored and GitHub committed 2026-11-15 09:35:10 -05:00
1 parent 9ce6d45be8
commit 52e8028609
2 files changed
+18 -2

No files matched your search

@@ -112,6 +112,10 @@ private const val HISTORY_LIMIT = 50
internal fun canNavigateUp(currentDir: File, currentRoot: File): Boolean =
currentDir != currentRoot && currentDir.parentFile?.exists() == true
// Back leaves after a drive hop instead of replaying a stack of hops one press at a time.
internal fun backExitsAtRootHop(currentDir: File, currentRoot: File, previous: Pair<File, File>): Boolean =
currentDir == currentRoot && previous.first == previous.second
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun FileManagerScreen(
@@ -269,8 +273,10 @@ fun FileManagerScreen(
if (showFavorites) showFavorites = false
else {
while (history.isNotEmpty() && !history.last().first.isDirectory) history.removeAt(history.lastIndex)
val previous = history.removeLastOrNull()
if (previous != null) {
val previous = history.lastOrNull()
if (previous != null && backExitsAtRootHop(currentDir, currentRoot, previous)) onExit?.invoke()
else if (previous != null) {
history.removeLastOrNull()
currentRoot = previous.second
loadDirectory(previous.first, record = false)
} else if (canNavigateUp(currentDir, currentRoot)) currentDir.parentFile?.let { loadDirectory(it, record = false) }