Skip to content

Commit 81cc6e8

Browse files
pane: When opening a buffer, actually scroll to the selected tab. (#3306)
Previously it might've reused a shared state. Deals with https://github.com/zed-industries/community/issues/2262 also fixes influencer's feedback. No gpui2 port, due to 0 scrollable functionality in it yet. Release Notes: - Fixed tabs not being scrolled to on buffer (re)open (https://github.com/zed-industries/community/issues/2262)
2 parents 6c6fb99 + f0f0b47 commit 81cc6e8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

crates/gpui/src/elements/flex.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,21 @@ impl<V: 'static> Flex<V> {
6767
where
6868
Tag: 'static,
6969
{
70+
// Don't assume that this initialization is what scroll_state really is in other panes:
71+
// `element_state` is shared and there could be init races.
7072
let scroll_state = cx.element_state::<Tag, Rc<ScrollState>>(
7173
element_id,
7274
Rc::new(ScrollState {
73-
scroll_to: Cell::new(scroll_to),
74-
scroll_position: Default::default(),
7575
type_tag: TypeTag::new::<Tag>(),
76+
scroll_to: Default::default(),
77+
scroll_position: Default::default(),
7678
}),
7779
);
80+
// Set scroll_to separately, because the default state is already picked as `None` by other panes
81+
// by the time we start setting it here, hence update all others' state too.
82+
scroll_state.update(cx, |this, _| {
83+
this.scroll_to.set(scroll_to);
84+
});
7885
self.scroll_state = Some((scroll_state, cx.handle().id()));
7986
self
8087
}

0 commit comments

Comments
 (0)