# Fix outline filtering always selecting last match \(\#50594\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 491ff012f7c8f4f5a8c72431eacfb6896b6907be

Requested commit: 491ff012f7c8f4f5a8c72431eacfb6896b6907be

Commit: 491ff012f7c8f4f5a8c72431eacfb6896b6907be

Tree: 3d916e62a2e0c3b97e5391769f8d6311c46abfae

Author: Om Chillure

Committer: GitHub

## Message

```
Fix outline filtering always selecting last match (#50594)

Fixes #29774

When filtering the outline panel, matches with equal fuzzy scores
previously defaulted to the last item due to iterator `max_by_key`
semantics. This caused the bottommost match (e.g. `C::f`) to always be
pre-selected regardless of cursor position.

Changes:
- Select the match nearest to the cursor when scores are tied, using a
multi-criteria comparison: score -> cursor containment depth ->
proximity to cursor -> earlier index
- Move outline search off the UI thread (`smol::block_on` -> async
`cx.spawn_in`) to avoid blocking during filtering
- Wrap `Outline<Anchor>` in `Arc` for cheap cloning into the async task
- Add `match_update_count` to discard results from stale queries

Tests : 
Adds a regression test:
`test_outline_filtered_selection_prefers_cursor_proximity_over_last_tie`
which passes

Video : 
[Screencast from 2026-03-03
17-01-32.webm](https://github.com/user-attachments/assets/7a27eaed-82a0-4990-85af-08c5a781f269)


Release Notes:
Fixed the outline filtering always select last match

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
```

## Parents

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

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