Skip to content

Commit 4ec717d

Browse files
committed
take "error" result from binary search into account
1 parent 6d62241 commit 4ec717d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4848
* disable blame and history popup keybinds for untracked files [[@kpbaks](https://github.com/kpbaks)] ([#2489](https://github.com/gitui-org/gitui/pull/2489))
4949
* overwrites committer on amend of unsigned commits [[@cruessler](https://github.com/cruessler)] ([#2784](https://github.com/gitui-org/gitui/issues/2784))
5050
* Updated project links to point to `gitui-org` instead of `extrawurst` [[@vasleymus](https://github.com/vasleymus)] ([#2538](https://github.com/gitui-org/gitui/pull/2538))
51+
* when staging the last file in a directory, the first item after the directory is no longer skipped [[@Tillerino](https://github.com/Tillerino)] ([#2748](https://github.com/gitui-org/gitui/issues/2748))
5152

5253
## [0.27.0] - 2024-01-14
5354

src/components/utils/statustree.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ impl StatusTree {
202202
return None;
203203
}
204204

205-
if let Ok(i) = self.tree.items().binary_search_by(|e| {
205+
let res = self.tree.items().binary_search_by(|e| {
206206
e.info.full_path.as_str().cmp(last_selection)
207-
}) {
208-
return Some(i);
207+
});
208+
match res {
209+
Ok(i) => Some(i),
210+
Err(i) => Some(cmp::min(i, self.tree.len() - 1)),
209211
}
210-
211-
Some(cmp::min(last_index, self.tree.len() - 1))
212212
}
213213

214214
fn selection_updown(
@@ -520,7 +520,7 @@ mod tests {
520520
res.update(&string_vec_to_status(&["a", "b"])).unwrap();
521521
res.selection = Some(1);
522522

523-
res.update(&string_vec_to_status(&["d", "c", "a"])).unwrap();
523+
res.update(&string_vec_to_status(&["a", "c", "d"])).unwrap();
524524
assert_eq!(res.selection, Some(1));
525525
}
526526

@@ -545,6 +545,21 @@ mod tests {
545545
assert_eq!(res.selection, Some(0));
546546
}
547547

548+
#[test]
549+
fn test_next_when_dir_disappears() {
550+
let mut res = StatusTree::default();
551+
res.update(&string_vec_to_status(&["a/b", "c", "d"]))
552+
.unwrap();
553+
res.selection = Some(1);
554+
assert_eq!(
555+
res.selected_item().unwrap().info.full_path,
556+
"a/b"
557+
);
558+
559+
res.update(&string_vec_to_status(&["c", "d"])).unwrap();
560+
assert_eq!(res.selected_item().unwrap().info.full_path, "c");
561+
}
562+
548563
#[test]
549564
fn test_keep_collapsed_states() {
550565
let mut res = StatusTree::default();

0 commit comments

Comments
 (0)