mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 02:46:17 +04:00
fix: avoid child area overflow on split (#10620)
This commit is contained in:
parent
e2594b64c0
commit
8db93013fb
@ -407,11 +407,13 @@ pub fn recalculate(&mut self) {
|
|||||||
}
|
}
|
||||||
Layout::Vertical => {
|
Layout::Vertical => {
|
||||||
let len = container.children.len();
|
let len = container.children.len();
|
||||||
|
let len_u16 = len as u16;
|
||||||
let width = area.width / len as u16;
|
|
||||||
|
|
||||||
let inner_gap = 1u16;
|
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;
|
let mut child_x = area.x;
|
||||||
|
|
||||||
@ -925,13 +927,43 @@ fn all_vertical_views_have_same_width() {
|
|||||||
assert_eq!(3, tree.views().count());
|
assert_eq!(3, tree.views().count());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec![
|
vec![
|
||||||
tree_area_width / 3,
|
tree_area_width / 3 - 1, // gap here
|
||||||
tree_area_width / 3,
|
tree_area_width / 3 - 1, // gap here
|
||||||
tree_area_width / 3 - 2 // Rounding in `recalculate`.
|
tree_area_width / 3
|
||||||
],
|
],
|
||||||
tree.views()
|
tree.views()
|
||||||
.map(|(view, _)| view.area.width)
|
.map(|(view, _)| view.area.width)
|
||||||
.collect::<Vec<_>>()
|
.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…
Reference in New Issue
Block a user