editor: Stabilize IME candidate box position during pre-edit on Wayland - #28429
Conversation
Modify the `replace_and_mark_text_in_range` method in the `Editor` to keep the cursor at the start of the preedit range during IME composition. Previously, the cursor would move to the end of the preedit text with each update, causing the IME candidate box to shift (e.g., when typing pinyin with Fcitx5 on Wayland). This change ensures the cursor and candidate box remain fixed until the composition is committed, improving the IME experience. Fixes #21004
|
We require contributors to sign our Contributor License Agreement, and we don't have @WantenMN on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
We require contributors to sign our Contributor License Agreement, and we don't have @WantenMN on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
I think the code changes were made in the wrong place. While everything works fine on Windows and macOS, the issue appears to be specifically with the Linux implementation. Your current changes affect behavior across all platforms when they should likely target Linux specifically. Windows: 2025-04-09.235340.mp4 |
You're right, I'll revert the changes and work on a better approach to fix the issue. |
…sition" This reverts commit e4fe197.
|
I believe that the cursor moving continuously while typing is expected behavior and shouldn’t be addressed with a hack. The issue of the IME candidate box shifting with the cursor is a problem with the input method itself, not the editor. Instead of modifying the editor’s code, it would be more appropriate to submit a pull request to the IME to ensure the candidate box remains fixed at its initial position. |
…on Wayland Replace `selected_text_range` with `marked_text_range` in `WaylandWindowStatePtr` to fix the IME candidate box movement issue on Linux Wayland. The previous implementation caused the candidate box to follow the cursor due to `selected_text_range` always returning the cursor's current position. Using `marked_text_range` ensures the candidate box remains fixed at the initial pre-edit position, improving usability for input methods like Fcitx5. Resolves #21004
|
I’ve updated the fix for this issue in my latest commit (d6ccb78). I realized the issue was with One thing I noticed: It’s unclear to me why Here are some screenshots: |
There was a problem hiding this comment.
selection.reversed
This is to model the case when the user selects from bottom to top, e.g.:
-------<|---------|----------
If the user starts their selection at | and then moves to <|, then the selection will be marked as "reversed", but the range will still be in order relative to the buffer contents. Therefore, the correct side to query should be the "start", whereas in this case:
-------|---------|>----------
If the user starts their selection at | and then moves to |>, then the selection will not be marked as "reversed", the correct side to query should be the "end"
Otherwise, this change seems pretty good!
|
@WantenMN Hello, looks like this PR requires a rebase on main |
|
Hey @JunkuiZhang last pr merge broke the ci. I have a pr open: #32049. I believe this pr will be fixed once we have this on main. |
|
@imumesh18 Thanks for the fix! |
|
Still requires a rebase I think, tests failed even that pr was merged |
Head branch was pushed to by a user without write access
|
Thanks! |
…on Wayland (zed-industries#28429)" This reverts commit 5d0c968.
…on Wayland (zed-industries#28429)" This reverts commit 5d0c968.
…nd (zed-industries#28429) Modify the `replace_and_mark_text_in_range` method in the `Editor` to keep the cursor at the start of the preedit range during IME composition. Previously, the cursor would move to the end of the preedit text with each update, causing the IME candidate box to shift (e.g., when typing pinyin with Fcitx5 on Wayland). This change ensures the cursor and candidate box remain fixed until the composition is committed, improving the IME experience. Closes zed-industries#21004 Release Notes: - N/A --------- Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com> Co-authored-by: 张小白 <364772080@qq.com>




Modify the
replace_and_mark_text_in_rangemethod in theEditorto keep the cursor at the start of the preedit range during IME composition. Previously, the cursor would move to the end of the preedit text with each update, causing the IME candidate box to shift (e.g., when typing pinyin with Fcitx5 on Wayland). This change ensures the cursor and candidate box remain fixed until the composition is committed, improving the IME experience.Closes #21004
Release Notes: