brain: Keep comment hunks bounded
8a78e3c3c0b0fa809a1aecbb998e0f004f5941eb
Keep the canonical review document separate from the viewer's expanded context so comment mode isolates and highlights the focused hunk correctly. Assisted-by: Codex:gpt-5.6
1 parent
c4d40242
crates/brain/src/session.rs
+13 -5
| 1415 | 1415 | ||
| 1416 | 1416 | let files: Vec<FileDiff> = loaded |
|
| 1417 | 1417 | .document |
|
| 1418 | 1418 | .files |
|
| 1419 | 1419 | .iter() |
|
| 1420 | - | .map(|file| { |
|
| 1421 | - | let mut file = file.clone(); |
|
| 1422 | - | if matches!(hunk_visibility, HunkVisibility::Pending) |
|
| 1423 | - | && !loaded.viewer.is_file_expanded(file.id) |
|
| 1424 | - | { |
|
| 1420 | + | .map(|original| { |
|
| 1421 | + | if loaded.viewer.is_file_expanded(original.id) { |
|
| 1422 | + | return loaded |
|
| 1423 | + | .viewer |
|
| 1424 | + | .document() |
|
| 1425 | + | .files |
|
| 1426 | + | .iter() |
|
| 1427 | + | .find(|file| file.id == original.id) |
|
| 1428 | + | .cloned() |
|
| 1429 | + | .unwrap_or_else(|| original.clone()); |
|
| 1430 | + | } |
|
| 1431 | + | let mut file = original.clone(); |
|
| 1432 | + | if matches!(hunk_visibility, HunkVisibility::Pending) { |
|
| 1425 | 1433 | file.hunks |
|
| 1426 | 1434 | .retain(|hunk| !loaded.review.is_accepted(hunk.id)); |
|
| 1427 | 1435 | } |
|
| 1428 | 1436 | file |
|
| 1429 | 1437 | }) |
a.rs
+0 -0
crates/brain/src/session/commit.rs
+0 -10
| 198 | 198 | if let Some(id) = hunk_ids.get_mut(&(file.id, patch_id)).and_then(Vec::pop) { |
|
| 199 | 199 | file.hunks[index].id = id; |
|
| 200 | 200 | } |
|
| 201 | 201 | } |
|
| 202 | 202 | } |
|
| 203 | - | for replacement in update.files() { |
|
| 204 | - | if let Some(file) = self |
|
| 205 | - | .document |
|
| 206 | - | .files |
|
| 207 | - | .iter_mut() |
|
| 208 | - | .find(|file| file.id == replacement.id) |
|
| 209 | - | { |
|
| 210 | - | *file = replacement.clone(); |
|
| 211 | - | } |
|
| 212 | - | } |
|
| 213 | 203 | self.viewer.apply_context_update(update, area); |
|
| 214 | 204 | Ok(()) |
|
| 215 | 205 | } |
|
| 216 | 206 | } |
|
| 217 | 207 |
a.rs
+0 -0