Skip to content

Commit 4f157bf

Browse files
committed
fix make check errors
1 parent 4cd425f commit 4f157bf

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
* allow `copy` file path on revision files and status tree [[@yanganto]](https://github.com/yanganto) ([#1516](https://github.com/extrawurst/gitui/pull/1516))
3737
* print message of where log will be written if `-l` is set ([#1472](https://github.com/extrawurst/gitui/pull/1472))
3838
* show remote branches in log [[@cruessler](https://github.com/cruessler)] ([#1501](https://github.com/extrawurst/gitui/issues/1501))
39+
* support 'n'/'p' key to move to the next/prev hunk in diff component [[@hamflx](https://github.com/hamflx)] ([#1523](https://github.com/extrawurst/gitui/issues/1523))
3940

4041
### Fixes
4142
* fixed side effect of crossterm 0.26 on windows that caused double input of all keys [[@pm100]](https://github/pm100) ([#1686](https://github.com/extrawurst/gitui/pull/1686))

src/components/diff.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -637,24 +637,15 @@ impl DiffComponent {
637637
if diff.hunks.is_empty() {
638638
return None;
639639
}
640-
let max = diff.hunks.len() as isize - 1;
641-
let target_index = self
642-
.selected_hunk
643-
.map(|i| {
644-
std::cmp::max(
645-
0,
646-
std::cmp::min(max, i as isize + direction),
647-
)
648-
})
649-
.unwrap_or(0) as usize;
640+
let max = diff.hunks.len() - 1;
641+
let target_index = self.selected_hunk.map_or(0, |i| {
642+
std::cmp::min(max, i.saturating_add_signed(direction))
643+
});
650644
Some(target_index)
651645
}
652646

653647
fn diff_hunk_move_up_down(&mut self, direction: isize) {
654-
let diff = match &self.diff {
655-
Some(diff) => diff,
656-
None => return,
657-
};
648+
let Some(diff) = &self.diff else { return };
658649
let target_index = self.calc_hunk_move_target(direction);
659650
// return if selected_hunk not change
660651
if self.selected_hunk == target_index {
@@ -820,7 +811,7 @@ impl Component for DiffComponent {
820811
CommandBlocking::PassingOn
821812
}
822813

823-
#[allow(clippy::cognitive_complexity)]
814+
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
824815
fn event(&mut self, ev: &Event) -> Result<EventState> {
825816
if self.focused() {
826817
if let Event::Key(e) = ev {

0 commit comments

Comments
 (0)