|
1411 | 1411 | } |
1412 | 1412 | } |
1413 | 1413 |
|
1414 | | - void fetchEntryUnderCursor() |
1415 | | - void fetchListingStats() |
1416 | | -
|
1417 | | - // Diff-driven selection adjustment: re-resolve selected names to new indices |
1418 | | - if (operationSelectedNames !== null && operationSelectedNames !== 'all') { |
1419 | | - diffGeneration++ |
1420 | | - const myGeneration = diffGeneration |
1421 | | - void findFileIndices(listingId, operationSelectedNames, includeHidden).then((nameToIndexMap) => { |
1422 | | - if (myGeneration !== diffGeneration) return |
1423 | | - selection.setSelectedIndices(buildFrontendIndices(nameToIndexMap, hasParent)) |
1424 | | - }) |
1425 | | - } |
1426 | | -
|
1427 | | - // Adjust cursor and selection after structural diffs (adds/removes) |
| 1414 | + // Adjust cursor and selection BEFORE fetching entry under cursor, |
| 1415 | + // otherwise fetchEntryUnderCursor uses the old index against the |
| 1416 | + // new (shorter) listing, causing "index out of bounds" errors. |
1428 | 1417 | const hasStructuralChanges = diff.changes.some((c) => c.type === 'add' || c.type === 'remove') |
1429 | 1418 | if (hasStructuralChanges) { |
1430 | 1419 | const removeIndices = diff.changes.filter((c) => c.type === 'remove').map((c) => c.index) |
1431 | 1420 | const addIndices = diff.changes.filter((c) => c.type === 'add').map((c) => c.index) |
1432 | 1421 |
|
1433 | 1422 | const offset = hasParent ? 1 : 0 |
1434 | 1423 |
|
1435 | | - // Selection: only adjust outside operations (operations handle via findFileIndices) |
1436 | | - if (operationSelectedNames === null && selection.selectedIndices.size > 0) { |
1437 | | - const backendSelected = selection.getSelectedIndices().map((i) => i - offset) |
1438 | | - const adjusted = adjustSelectionIndices(backendSelected, removeIndices, addIndices) |
1439 | | - selection.setSelectedIndices(adjusted.map((i) => i + offset)) |
1440 | | - } |
1441 | | -
|
1442 | 1424 | // Cursor: always adjust (no operation-specific cursor handling exists) |
1443 | 1425 | const backendCursor = cursorIndex - offset |
1444 | 1426 | const adjustedCursor = adjustSelectionIndices([backendCursor], removeIndices, addIndices) |
|
1447 | 1429 | } else { |
1448 | 1430 | cursorIndex = Math.max(0, Math.min(cursorIndex, count - 1 + offset)) |
1449 | 1431 | } |
| 1432 | +
|
| 1433 | + // Selection: only adjust outside operations (operations handle via findFileIndices) |
| 1434 | + if (operationSelectedNames === null && selection.selectedIndices.size > 0) { |
| 1435 | + const backendSelected = selection.getSelectedIndices().map((i) => i - offset) |
| 1436 | + const adjusted = adjustSelectionIndices(backendSelected, removeIndices, addIndices) |
| 1437 | + selection.setSelectedIndices(adjusted.map((i) => i + offset)) |
| 1438 | + } |
| 1439 | + } |
| 1440 | +
|
| 1441 | + void fetchEntryUnderCursor() |
| 1442 | + void fetchListingStats() |
| 1443 | +
|
| 1444 | + // Diff-driven selection adjustment: re-resolve selected names to new indices |
| 1445 | + if (operationSelectedNames !== null && operationSelectedNames !== 'all') { |
| 1446 | + diffGeneration++ |
| 1447 | + const myGeneration = diffGeneration |
| 1448 | + void findFileIndices(listingId, operationSelectedNames, includeHidden).then((nameToIndexMap) => { |
| 1449 | + if (myGeneration !== diffGeneration) return |
| 1450 | + selection.setSelectedIndices(buildFrontendIndices(nameToIndexMap, hasParent)) |
| 1451 | + }) |
1450 | 1452 | } |
1451 | 1453 | }) |
1452 | 1454 | }) |
|
0 commit comments