Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid child area overflow on split #10620

Merged
merged 1 commit into from
Apr 29, 2024
Merged
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
44 changes: 38 additions & 6 deletions helix-view/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,13 @@ impl Tree {
}
Layout::Vertical => {
let len = container.children.len();

let width = area.width / len as u16;
let len_u16 = len as u16;

let inner_gap = 1u16;
// let total_gap = inner_gap * (len as u16 - 1);
let total_gap = inner_gap * len_u16.saturating_sub(2);

let used_area = area.width.saturating_sub(total_gap);
let width = used_area / len_u16;

let mut child_x = area.x;

Expand Down Expand Up @@ -925,13 +927,43 @@ mod test {
assert_eq!(3, tree.views().count());
assert_eq!(
vec![
tree_area_width / 3,
tree_area_width / 3,
tree_area_width / 3 - 2 // Rounding in `recalculate`.
tree_area_width / 3 - 1, // gap here
tree_area_width / 3 - 1, // gap here
tree_area_width / 3
],
tree.views()
.map(|(view, _)| view.area.width)
.collect::<Vec<_>>()
);
}

#[test]
fn vsplit_gap_rounding() {
let (tree_area_width, tree_area_height) = (80, 24);
let mut tree = Tree::new(Rect {
x: 0,
y: 0,
width: tree_area_width,
height: tree_area_height,
});
let mut view = View::new(DocumentId::default(), GutterConfig::default());
view.area = Rect::new(0, 0, tree_area_width, tree_area_height);
tree.insert(view);

for _ in 0..9 {
let view = View::new(DocumentId::default(), GutterConfig::default());
tree.split(view, Layout::Vertical);
}

assert_eq!(10, tree.views().count());
assert_eq!(
std::iter::repeat(7)
.take(9)
.chain(Some(8)) // Rounding in `recalculate`.
.collect::<Vec<_>>(),
tree.views()
.map(|(view, _)| view.area.width)
.collect::<Vec<_>>()
);
}
}
Loading