|
1414 | 1414 | }) |
1415 | 1415 | } |
1416 | 1416 |
|
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 | + } |
1431 | 1431 |
|
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)) |
1439 | 1439 | } |
1440 | 1440 | } |
1441 | 1441 | }) |
|
0 commit comments