From f0f0b4705876e0b7c5692bfcb4895df8593feb52 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 13 Nov 2023 13:09:02 +0200 Subject: [PATCH] pane: When opening a buffer, actually scroll to the selected tab. Previously it might've reused a shared state. Deals with https://github.com/zed-industries/community/issues/2262 also fixes influencer's feedback. Co-Authored-By: Piotr --- crates/gpui/src/elements/flex.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/gpui/src/elements/flex.rs b/crates/gpui/src/elements/flex.rs index ba387c5e48..f4b8578d17 100644 --- a/crates/gpui/src/elements/flex.rs +++ b/crates/gpui/src/elements/flex.rs @@ -67,14 +67,21 @@ impl Flex { where Tag: 'static, { + // Don't assume that this initialization is what scroll_state really is in other panes: + // `element_state` is shared and there could be init races. let scroll_state = cx.element_state::>( element_id, Rc::new(ScrollState { - scroll_to: Cell::new(scroll_to), - scroll_position: Default::default(), type_tag: TypeTag::new::(), + scroll_to: Default::default(), + scroll_position: Default::default(), }), ); + // Set scroll_to separately, because the default state is already picked as `None` by other panes + // by the time we start setting it here, hence update all others' state too. + scroll_state.update(cx, |this, _| { + this.scroll_to.set(scroll_to); + }); self.scroll_state = Some((scroll_state, cx.handle().id())); self }