# Fix inlay hint hover highlight for multi-byte UTF-8 characters \(\#44872\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 848d3cc34e64658463b112397e8ae656ac4d7100

Requested commit: 848d3cc34e64658463b112397e8ae656ac4d7100

Commit: 848d3cc34e64658463b112397e8ae656ac4d7100

Tree: d713819db32acfebde6fb06ceea2108d55fda5f3

Author: rari404

Committer: GitHub

## Message

````
Fix inlay hint hover highlight for multi-byte UTF-8 characters (#44872)

## Summary

Fixes #44812

The hover highlight for clickable inlay hints was not covering the last
character when the label contained multi-byte UTF-8 characters (e.g.,
`→`).

## Problem

When hovering over an inlay hint like `→ app/Livewire/UserProfile.php`,
the highlight/underline stopped one character short, leaving the final
character unhighlighted.

**Root cause:** `find_hovered_hint_part()` in `hover_popover.rs` used
`part.value.chars().count()` (character count) but `InlayOffset` wraps
`MultiBufferOffset(pub usize)` which is byte-based.

For a label like `→ app/Livewire/UserProfile.php`:
- Byte length: 32 (the `→` character is 3 bytes in UTF-8)
- Character count: 30

This mismatch caused the calculated highlight range to end 2 bytes
short.

## Changes

1. **Use byte length instead of character count** (line 112):
   ```rust
   // Before (buggy)
   let part_len = part.value.chars().count();
   
   // After (correct)
   let part_len = part.value.len();
   ```

2. **Fix boundary condition** (line 113): Changed `>` to `>=` for
correct `[start, end)` range semantics when hovering at part boundaries.

3. **Rename variable** for clarity: `hovered_character` →
`offset_in_hint` since it's a byte offset, not a character position.

4. **Add unit test** reproducing the exact scenario from the issue with
multi-byte UTF-8 characters.

## Testing

Added `test_find_hovered_hint_part_with_multibyte_characters` which:
- Verifies the label `→ app/Livewire/UserProfile.php` has 32 bytes but
30 characters
- Tests hovering at the last byte correctly returns the full range
- Tests boundary behavior with multiple label parts containing
multi-byte characters

Release Notes:

- Fixed inlay hint hover highlight not covering the last character when
the label contains multi-byte UTF-8 characters
````

## Parents

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

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