Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* print slightly nicer errors when failing to create a directory [[@linkmauve](https://github.com/linkmauve)] (https://github.com/gitui-org/gitui/pull/2728)
* When the terminal is insufficient to display all the commands, the cmdbar_bg configuration color does not fully take effect. ([#2347](https://github.com/extrawurst/gitui/issues/2347))
* disable blame and history popup keybinds for untracked files [[@kpbaks](https://github.com/kpbaks)] ([#2489](https://github.com/gitui-org/gitui/pull/2489))
* 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))

## [0.27.0] - 2024-01-14

Expand Down
27 changes: 21 additions & 6 deletions src/components/utils/statustree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ impl StatusTree {
return None;
}

if let Ok(i) = self.tree.items().binary_search_by(|e| {
let res = self.tree.items().binary_search_by(|e| {
e.info.full_path.as_str().cmp(last_selection)
}) {
return Some(i);
});
match res {
Ok(i) => Some(i),
Err(i) => Some(cmp::min(i, self.tree.len() - 1)),
}

Some(cmp::min(last_index, self.tree.len() - 1))
}

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

res.update(&string_vec_to_status(&["d", "c", "a"])).unwrap();
res.update(&string_vec_to_status(&["a", "c", "d"])).unwrap();
Copy link
Author

@Tillerino Tillerino Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to sort the list to keep this test working. The binary search assumes that the status list is sorted, but this is never validated in the status tree. I think this test used to pass accidentally, since the list is so short.

assert_eq!(res.selection, Some(1));
}

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

#[test]
fn test_next_when_dir_disappears() {
let mut res = StatusTree::default();
res.update(&string_vec_to_status(&["a/b", "c", "d"]))
.unwrap();
res.selection = Some(1);
assert_eq!(
res.selected_item().unwrap().info.full_path,
"a/b"
);

res.update(&string_vec_to_status(&["c", "d"])).unwrap();
assert_eq!(res.selected_item().unwrap().info.full_path, "c");
Copy link
Author

@Tillerino Tillerino Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, the selection skips c and jumps straight to d.

}

#[test]
fn test_keep_collapsed_states() {
let mut res = StatusTree::default();
Expand Down