# editor: Do not highlight selected text \+ Clear highlight preemptively when new selection is detected \(\#25149\) · gitcafe/zed

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

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

Visibility: public

Requested revision: fb19db00ca15085a3363ce21dbe2e5cfa68dc687

Requested commit: fb19db00ca15085a3363ce21dbe2e5cfa68dc687

Commit: fb19db00ca15085a3363ce21dbe2e5cfa68dc687

Tree: 39830f81d552450beda242e4b819f9a6d935ea10

Author: smit

Committer: GitHub

## Message

```
editor: Do not highlight selected text + Clear highlight preemptively when new selection is detected  (#25149)

When selecting text, it highlights all matching occurences along with
selected text itself. This causes highlight overlap, which looks bit
odd. This PR fixes it.

Bonus:

Context: We have an edge case (which we already cover) where we don’t
want to clear `SelectedTextHighlight` every time the selection changes.
This happens when you are dragging the selection across some word, if
you clear it directly on selection change, due to debounce wait, the
highlight take some time to appear, which causes flickering for the
user. We solve this by not clearing it directly but only clearing it
when a new selection is found. This avoids the flicker.

However, we also need to clear the selection even before the debounce
wait if we detect early on that the selection is different from previous
ones. Otherwise, the user will have to wait until the debounce time to
see it cleared on the screen.

The code for this is a little repetitive because we check the buffer
state both before and after the debounce. But this is necessary.

---
Before:

Notice overlapping corners and selected text is bit darker in this case.

![image](https://github.com/user-attachments/assets/ec371079-b513-4216-9f6e-73d1aff99250)

After:

![image](https://github.com/user-attachments/assets/0fb9cd58-5d4b-49e8-91cb-78999c3a54a8)

Release Notes:

- N/A
```

## Parents

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

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