diff: Fix `n` key on initial load
6a26964ecd45e494e5d7dd7029cfc07794ec9050
The key was not having any effect previously.
1 parent
a0375398
crates/diff/src/viewer.rs
+17 -6
| 1364 | 1364 | return; |
|
| 1365 | 1365 | } |
|
| 1366 | 1366 | let current = self |
|
| 1367 | 1367 | .state |
|
| 1368 | 1368 | .focus |
|
| 1369 | - | .and_then(|focus| targets.iter().position(|target| target.focus == focus)); |
|
| 1369 | + | .and_then(|focus| targets.iter().position(|target| target.focus == focus)) |
|
| 1370 | + | .or_else(|| { |
|
| 1371 | + | if filter != FocusFilter::File { |
|
| 1372 | + | return None; |
|
| 1373 | + | } |
|
| 1374 | + | self.file_row_location(self.state.scroll.offset) |
|
| 1375 | + | .and_then(|location| { |
|
| 1376 | + | targets |
|
| 1377 | + | .iter() |
|
| 1378 | + | .position(|target| target.focus == DiffFocus::File(location.file.id)) |
|
| 1379 | + | }) |
|
| 1380 | + | }); |
|
| 1370 | 1381 | let next = match (current, delta.is_negative()) { |
|
| 1371 | - | (Some(index), true) => index.saturating_sub(1), |
|
| 1372 | - | (Some(index), false) => index.saturating_add(1).min(targets.len() - 1), |
|
| 1373 | - | (None, true) => targets.len() - 1, |
|
| 1374 | - | (None, false) => 0, |
|
| 1382 | + | (Some(index), true) => index.checked_sub(1), |
|
| 1383 | + | (Some(index), false) => index.checked_add(1).filter(|index| *index < targets.len()), |
|
| 1384 | + | (None, true) => targets.len().checked_sub(1), |
|
| 1385 | + | (None, false) => Some(0), |
|
| 1375 | 1386 | }; |
|
| 1376 | - | let Some(target) = targets.get(next) else { |
|
| 1387 | + | let Some(target) = next.and_then(|next| targets.get(next)) else { |
|
| 1377 | 1388 | return; |
|
| 1378 | 1389 | }; |
|
| 1379 | 1390 | ||
| 1380 | 1391 | self.state.focus = Some(target.focus); |
|
| 1381 | 1392 | if filter == FocusFilter::File { |
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0
src/a.rs
+0 -0
src/b.rs
+0 -0
README.md
+0 -0
src/app/a.rs
+0 -0
src/lib/b.rs
+0 -0
README.md
+0 -0
a.rs
+0 -0
b.rs
+0 -0
assets/css/style.css
+0 -0
assets/css/style.css
+0 -0
a.rs
+0 -0
a.rs
+0 -0
a.rs
+0 -0
b.rs
+0 -0