Skip to content

Commit 2cbd43e

Browse files
fix(web): preserve diff tree focus across path aliases
1 parent d9dc410 commit 2cbd43e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎apps/web/src/components/diffs/DiffFileTree.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ export function DiffFileTree({
110110
const updates = buildDiffFileTreeUpdates(mounted.paths, modelPaths);
111111
if (updates.length > 0) model.batch(updates);
112112
} else {
113-
// A reset can turn a selected file path into a directory. Carry selection
113+
// A reset can turn a file path into a directory. Carry selection and focus
114114
// through real paths so paging keeps the same file without revealing it again.
115+
const focusedPath = model.getFocusedPath();
116+
const nextFocusedPath =
117+
focusedPath === null ? null : presented.modelPath(mounted.selectionPath(focusedPath));
115118
const selectedPaths = model
116119
.getSelectedPaths()
117120
.map((path) => presented.modelPath(mounted.selectionPath(path)))
@@ -131,6 +134,12 @@ export function DiffFileTree({
131134
const directory = model.getItem(path);
132135
if (directory !== null && "collapse" in directory) directory.collapse();
133136
}
137+
if (
138+
nextFocusedPath !== null &&
139+
(modelPaths.includes(nextFocusedPath) || directoryPaths.includes(nextFocusedPath))
140+
) {
141+
model.focusPath(nextFocusedPath);
142+
}
134143
}
135144
model.setGitStatus(gitStatus);
136145
}, [directoryPaths, gitStatus, model, modelPaths, ordering, positions, presented]);

0 commit comments

Comments
 (0)