zed/crates/language
Tim Vermeulen 1e6e44874e
editor: Fix autoscroll sometimes obscuring the current row behind a sticky header (#53165)
Fixes an autoscroll bug that sometimes obscures the current row behind a
sticky header.

The bug was caused by `Editor::autoscroll_vertically` using the
`sticky_header_line_count` value that was cached during the previous
render, which isn't necessarily the number of sticky headers that the
scroll target needs, e.g.
- when jumping to a definition
- when pressing the up arrow key when the selection is in the topmost
visible row with `"vertical_scroll_margin": 0`

This fixes that by not caching `sticky_header_line_count` and instead
querying Tree-sitter on the fly to get the number of sticky headers that
the scroll target needs. Performance-wise this seem okay, I measured it
to take less than 200µs on my machine using a very large Rust file (and
there are still some possible ways to optimize this if necessary). In
particular, the pathological huge single-line file case as discussed in
#48450 shouldn't be an issue here because unlike the main sticky header
Tree-sitter query, here we query the outline items that contain a
particular point rather than those that intersect an entire row.

The `ScrollCursorTop` handler is also simplified to use the same shared
function for counting the number of sticky headers, since that action
doesn't rely on autoscroll.

Before:


https://github.com/user-attachments/assets/efb12776-82d9-4b94-baa5-347ec769fb98

After:


https://github.com/user-attachments/assets/236deb9f-fe06-43bd-b167-7bd3ab719e4c

Self-Review Checklist:

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

Closes #50803 

Release Notes:

- Fixed sticky headers sometimes obscuring the current row.

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
2026-04-21 21:29:00 +00:00
..
benches Extract language_core and grammars crates from language (#52238) 2026-03-25 23:41:09 +00:00
src editor: Fix autoscroll sometimes obscuring the current row behind a sticky header (#53165) 2026-04-21 21:29:00 +00:00
build.rs
Cargo.toml theme: Split out theme_settings crate (#52569) 2026-03-27 14:41:25 +01:00
LICENSE-GPL