diff --git a/Cargo.lock b/Cargo.lock index d8681c4be0..53dbb11a59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4721,9 +4721,9 @@ dependencies = [ [[package]] name = "grid" -version = "0.11.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df00eed8d1f0db937f6be10e46e8072b0671accb504cf0f959c5c52c679f5b9" +checksum = "d196ffc1627db18a531359249b2bf8416178d84b729f3cebeb278f285fb9b58c" [[package]] name = "group" @@ -9976,12 +9976,14 @@ dependencies = [ [[package]] name = "taffy" -version = "0.3.11" -source = "git+https://github.com/DioxusLabs/taffy?rev=1876f72bee5e376023eaa518aa7b8a34c769bd1b#1876f72bee5e376023eaa518aa7b8a34c769bd1b" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2e140b328c6cb5e744bb2c65910b47df86b239afc793ee2c52262569cf9225" dependencies = [ "arrayvec", "grid", "num-traits", + "serde", "slotmap", ] diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 9b04445e07..93653f45de 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -3670,19 +3670,23 @@ impl Element for EditorElement { let editor_handle = cx.view().clone(); let max_line_number_width = self.max_line_number_width(&editor.snapshot(cx), cx); - cx.request_measured_layout(Style::default(), move |known_dimensions, _, cx| { - editor_handle - .update(cx, |editor, cx| { - compute_auto_height_layout( - editor, - max_lines, - max_line_number_width, - known_dimensions, - cx, - ) - }) - .unwrap_or_default() - }) + cx.request_measured_layout( + Style::default(), + move |known_dimensions, available_space, cx| { + editor_handle + .update(cx, |editor, cx| { + compute_auto_height_layout( + editor, + max_lines, + max_line_number_width, + known_dimensions, + available_space.width, + cx, + ) + }) + .unwrap_or_default() + }, + ) } EditorMode::Full => { let mut style = Style::default(); @@ -5261,9 +5265,16 @@ fn compute_auto_height_layout( max_lines: usize, max_line_number_width: Pixels, known_dimensions: Size>, + available_width: AvailableSpace, cx: &mut ViewContext, ) -> Option> { - let width = known_dimensions.width?; + let width = known_dimensions.width.or_else(|| { + if let AvailableSpace::Definite(available_width) = available_width { + Some(available_width) + } else { + None + } + })?; if let Some(height) = known_dimensions.height { return Some(size(width, height)); } diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index ed0e63f9db..f8ca20902b 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -61,7 +61,7 @@ slotmap = "1.0.6" smallvec.workspace = true smol.workspace = true sum_tree.workspace = true -taffy = { git = "https://github.com/DioxusLabs/taffy", rev = "1876f72bee5e376023eaa518aa7b8a34c769bd1b" } +taffy = "0.4.3" thiserror.workspace = true time.workspace = true util.workspace = true diff --git a/crates/gpui/src/taffy.rs b/crates/gpui/src/taffy.rs index 03ba16cd3e..16f887414e 100644 --- a/crates/gpui/src/taffy.rs +++ b/crates/gpui/src/taffy.rs @@ -9,14 +9,14 @@ use taffy::{ geometry::{Point as TaffyPoint, Rect as TaffyRect, Size as TaffySize}, style::AvailableSpace as TaffyAvailableSpace, tree::NodeId, - Taffy, + TaffyTree, TraversePartialTree as _, }; type NodeMeasureFn = Box>, Size, &mut WindowContext) -> Size>; pub struct TaffyLayoutEngine { - taffy: Taffy, + taffy: TaffyTree<()>, styles: FxHashMap, children_to_parents: FxHashMap, absolute_layout_bounds: FxHashMap>, @@ -29,7 +29,7 @@ static EXPECT_MESSAGE: &str = "we should avoid taffy layout errors by constructi impl TaffyLayoutEngine { pub fn new() -> Self { TaffyLayoutEngine { - taffy: Taffy::new(), + taffy: TaffyTree::new(), styles: FxHashMap::default(), children_to_parents: FxHashMap::default(), absolute_layout_bounds: FxHashMap::default(), @@ -114,7 +114,7 @@ impl TaffyLayoutEngine { fn max_depth(&self, depth: u32, parent: LayoutId) -> anyhow::Result { println!( "{parent:?} at depth {depth} has {} children", - self.taffy.child_count(parent.0)? + self.taffy.child_count(parent.0) ); let mut max_child_depth = 0;