Skip to content

Commit 644f76f

Browse files
committed
Use animation for compaction expand/collapse
1 parent 0bc3a8f commit 644f76f

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

crates/code_assistant/src/ui/gpui/elements.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,8 +1280,9 @@ impl BlockView {
12801280

12811281
fn toggle_compaction(&mut self, cx: &mut Context<Self>) {
12821282
if let Some(summary) = self.block.as_compaction_mut() {
1283-
summary.is_expanded = !summary.is_expanded;
1284-
cx.notify();
1283+
let should_expand = !summary.is_expanded;
1284+
summary.is_expanded = should_expand;
1285+
self.start_expand_collapse_animation(should_expand, cx);
12851286
}
12861287
}
12871288

@@ -2003,14 +2004,31 @@ impl Render for BlockView {
20032004
let mut container = div().mt_2().w_full().flex().flex_col();
20042005
container = container.child(header);
20052006

2006-
if is_expanded {
2007-
container = container.child(
2008-
div()
2009-
.px_3()
2010-
.pb_2()
2011-
.text_color(cx.theme().foreground)
2012-
.child(self.markdown_view(&block.summary, true, cx)),
2013-
);
2007+
// Animated expand/collapse for the summary content
2008+
let animation_scale = match &self.animation_state {
2009+
AnimationState::Animating { height_scale, .. } => *height_scale,
2010+
AnimationState::Idle => {
2011+
if is_expanded {
2012+
1.0
2013+
} else {
2014+
0.0
2015+
}
2016+
}
2017+
};
2018+
2019+
if is_expanded || animation_scale > 0.0 {
2020+
let body = div()
2021+
.px_3()
2022+
.pb_2()
2023+
.text_color(cx.theme().foreground)
2024+
.child(self.markdown_view(&block.summary, true, cx));
2025+
2026+
container =
2027+
container.child(crate::ui::gpui::tool_block_renderers::animated_card_body(
2028+
body,
2029+
animation_scale,
2030+
self.content_height.clone(),
2031+
));
20142032
}
20152033

20162034
container.into_any_element()

0 commit comments

Comments
 (0)