editor: Stabilize IME candidate box position during pre-edit on Wayland (#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 #21004

Release Notes:

- N/A

---------

Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
Co-authored-by: 张小白 <364772080@qq.com>
This commit is contained in:
Wanten 2025-06-04 17:14:01 +08:00 committed by GitHub
parent 071e684be4
commit 5d0c96872b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -635,12 +635,8 @@ impl WaylandWindowStatePtr {
let mut bounds: Option<Bounds<Pixels>> = None;
if let Some(mut input_handler) = state.input_handler.take() {
drop(state);
if let Some(selection) = input_handler.selected_text_range(true) {
bounds = input_handler.bounds_for_range(if selection.reversed {
selection.range.start..selection.range.start
} else {
selection.range.end..selection.range.end
});
if let Some(selection) = input_handler.marked_text_range() {
bounds = input_handler.bounds_for_range(selection.start..selection.start);
}
self.state.borrow_mut().input_handler = Some(input_handler);
}