SIGN IN SIGN UP

agent_ui: Prevent scrolling to the end when expanding context compaction (#62210)

# Objective

Prevent the thread from automatically scrolling to the end when
expanding a "Context Compacted" message at the end of the thread, as we
suspect the user would likely be trying to read it from top to bottom.

## Solution

Update how the `ThreadView` behaves when expanding a "Context Compacted"
message, namely by updating `ThreadView::toggle_compaction_expansion` in
order to anchor the scroll position, which disables the tail following
behavior, ensuring that the scroll offset is kept.

In order to better support this, a new method is introduced to
`gpui::elements::list::ListState`, `anchor_scroll_position`, which takes
the current scroll offset and scrolls to it which, in turns, disables
the following behavior.

Another option would be to simply introduce
`gpui::elements::list::ListState::stop_following` but I'm not sure
whether we'd want to expose that implementation detail, even though we
already have `gpui::elements::list::ListState::is_following_tail` .

## Testing

Tested both manually as well as introduced a new test for
`ListState::anchor_scroll_position`.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

## Showcase

<details>
  <summary>Before</summary>


https://github.com/user-attachments/assets/cf8ee10f-9c74-429d-afed-7a39ccd71c67
</details>

<details>
  <summary>After</summary>


https://github.com/user-attachments/assets/78edfca9-099a-4fdb-9c4e-75f790096957
</details>

---

Release Notes:

- Improved expanding "Context Compacted" messages in the Agent Panel to
ensure that the scroll position is preserved, instead of automatically
scrolling to the end of the thread.

---------

Co-authored-by: Joseph T. Lyons <JosephTLyons@gmail.com>
D
Dino committed
87e698fb6fd09e69a16c66ae83060ac1e3af3fd6
Parent: 6b2aa1c
Committed by GitHub <noreply@github.com> on 8/7/2026, 9:07:35 AM