# gpui: Anchor IME candidate window to the start of the visual line \(\#55876\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 737f55a1a14d3a95d776e2cfa32554f0fd03fbe7

Requested commit: 737f55a1a14d3a95d776e2cfa32554f0fd03fbe7

Commit: 737f55a1a14d3a95d776e2cfa32554f0fd03fbe7

Tree: 63df53397fde6147ff55c6d88876b88a768008a0

Author: Wanten

Committer: GitHub

## Message

```
gpui: Anchor IME candidate window to the start of the visual line (#55876)

## Summary

This PR fixes horizontal jumping of the IME candidate window during text
composition.

On the shared `selected_bounds` path used by Windows, the candidate
window no longer follows the preedit caret character-by-character.
Instead, it anchors to the start of the current visual line, which keeps
the candidate window stable while typing.

Linux Wayland uses a different IME positioning path, so it was not
affected by the original implementation in this PR. This PR now also
includes a Wayland-specific adjustment so that Wayland uses the same
visual-line anchoring behavior.

## Changes

1. **Shared / Windows path**
Updated `selected_bounds` in `crates/gpui/src/platform.rs` to use a
visual-line-aware anchor for preedit text.

This removes the distracting horizontal movement of the candidate window
while typing and keeps the anchor aligned with the active visual line.

2. **Linux Wayland path**
Updated the Wayland IME area calculation in
`crates/gpui_linux/src/linux/wayland/window.rs` to use the same
visual-line-start anchoring strategy for preedit text.

This brings Linux Wayland in line with the Windows behavior while
preserving Wayland's platform-specific IME handling.

## Notes

I had previously tried a separate Wayland-specific fix in
5d0c96872bc3aeed7405ab7bee668b8e77ec7430, but later reverted it in
8cfe7a2a54441f89c170fbdd165a49b3e787b3c4 because the behavior was not
good enough and it regressed the original positioning behavior.

The current Wayland implementation is a new, simpler approach that keeps
the original behavior intact while also removing horizontal
candidate-window jumping.

## Visuals

### Windows / shared path

* **Before the fix:** (The candidate box moves along with the preedit
text, which is distracting)
    
<img width="918" height="675" alt="before"
src="https://github.com/user-attachments/assets/29cb05e4-3e99-4b54-9ce3-78710b307ce6"
/>

<img width="478" height="682" alt="before_1"
src="https://github.com/user-attachments/assets/cff38b65-96dd-4ed7-b06b-7fbcd448fab9"
/>

* **After the fix:** (Candidate box stays fixed at the line start during
typing, correctly jumps to new lines or follows active segments)

<img width="918" height="675" alt="after"
src="https://github.com/user-attachments/assets/4f50a710-dc0d-4959-a313-1184122ab759"
/>

<img width="478" height="683" alt="after_1"
src="https://github.com/user-attachments/assets/8e9df121-ffcc-45ad-ba0b-f1ad3cef87bc"
/>

### Linux Wayland

*  **Before / previous behavior**

<img width="552" height="796" alt="before"
src="https://github.com/user-attachments/assets/e3e84312-c626-41cb-945f-66c13aa96df6"
/>


*  **After / current implementation**

<img width="546" height="772" alt="after"
src="https://github.com/user-attachments/assets/a01ab6d7-a3b6-4d56-a1cb-b2b112b6b914"
/>


---

## 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
*   [x] Tests cover the new/changed behavior (manual verification only)
*   [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A
```

## Parents

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

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