# editor: Fix autoscroll sometimes obscuring the current row behind a sticky header \(\#53165\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/1e6e44874edeabc377e40be217224a20d36bc31a)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 1e6e44874edeabc377e40be217224a20d36bc31a

Requested commit: 1e6e44874edeabc377e40be217224a20d36bc31a

Commit: 1e6e44874edeabc377e40be217224a20d36bc31a

Tree: 2bd7a8fc6d2c407fa0f61030379fcfbcd9b3282d

Author: Tim Vermeulen

Committer: GitHub

## Message

```
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>
```

## Parents

- [179af67c0fa13d2e3bb981a59c99151120295768](https://git.cafe/gitcafe/zed/commit/179af67c0fa13d2e3bb981a59c99151120295768?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/1e6e44874edeabc377e40be217224a20d36bc31a?format=markdown)
