Skip to content

Commit 17808d4

Browse files
committed
Bugfix: Cursor lost after deleting all files
- Cursor adjustment on structural diffs was gated behind `operationSelectedNames === null`, so it never ran during delete/move operations - Selection adjustment stays gated (operations handle it via `findFileIndices`), but cursor now always adjusts
1 parent 6d9479f commit 17808d4

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,28 +1414,28 @@
14141414
})
14151415
}
14161416
1417-
// Fallback: adjust selection and cursor for structural diffs outside file operations
1418-
if (operationSelectedNames === null) {
1419-
const hasStructuralChanges = diff.changes.some((c) => c.type === 'add' || c.type === 'remove')
1420-
if (hasStructuralChanges) {
1421-
const removeIndices = diff.changes.filter((c) => c.type === 'remove').map((c) => c.index)
1422-
const addIndices = diff.changes.filter((c) => c.type === 'add').map((c) => c.index)
1423-
1424-
const offset = hasParent ? 1 : 0
1425-
1426-
if (selection.selectedIndices.size > 0) {
1427-
const backendSelected = selection.getSelectedIndices().map((i) => i - offset)
1428-
const adjusted = adjustSelectionIndices(backendSelected, removeIndices, addIndices)
1429-
selection.setSelectedIndices(adjusted.map((i) => i + offset))
1430-
}
1417+
// Adjust cursor and selection after structural diffs (adds/removes)
1418+
const hasStructuralChanges = diff.changes.some((c) => c.type === 'add' || c.type === 'remove')
1419+
if (hasStructuralChanges) {
1420+
const removeIndices = diff.changes.filter((c) => c.type === 'remove').map((c) => c.index)
1421+
const addIndices = diff.changes.filter((c) => c.type === 'add').map((c) => c.index)
1422+
1423+
const offset = hasParent ? 1 : 0
1424+
1425+
// Selection: only adjust outside operations (operations handle via findFileIndices)
1426+
if (operationSelectedNames === null && selection.selectedIndices.size > 0) {
1427+
const backendSelected = selection.getSelectedIndices().map((i) => i - offset)
1428+
const adjusted = adjustSelectionIndices(backendSelected, removeIndices, addIndices)
1429+
selection.setSelectedIndices(adjusted.map((i) => i + offset))
1430+
}
14311431
1432-
const backendCursor = cursorIndex - offset
1433-
const adjustedCursor = adjustSelectionIndices([backendCursor], removeIndices, addIndices)
1434-
if (adjustedCursor.length > 0) {
1435-
cursorIndex = adjustedCursor[0] + offset
1436-
} else {
1437-
cursorIndex = Math.max(0, Math.min(cursorIndex, count - 1 + offset))
1438-
}
1432+
// Cursor: always adjust (no operation-specific cursor handling exists)
1433+
const backendCursor = cursorIndex - offset
1434+
const adjustedCursor = adjustSelectionIndices([backendCursor], removeIndices, addIndices)
1435+
if (adjustedCursor.length > 0) {
1436+
cursorIndex = adjustedCursor[0] + offset
1437+
} else {
1438+
cursorIndex = Math.max(0, Math.min(cursorIndex, count - 1 + offset))
14391439
}
14401440
}
14411441
})

0 commit comments

Comments
 (0)