mirror of
https://github.com/storytold/winit.git
synced 2026-11-20 19:30:41 +01:00
W27: Wayland set_ime_surrounding_text sends nothing when unchanged
Each commit makes the compositor send done, and input-method-v2 compositors ignore input-method commits against an older serial, so an app calling it every frame could lose typed text.
This commit is contained in:
1 parent
063cfe9e54
commit
e592e35d80
3 files changed
+22
-1
No files matched your search
@@ -165,7 +165,8 @@ pub trait WindowExtWayland {
|
||||
/// `anchor`; without a selection they are equal. Leave the preedit out of `text`. Offsets
|
||||
/// are clamped to the text and moved back to a character boundary, and text longer than
|
||||
/// 4000 bytes is cut around the cursor and selection. Call it again whenever the text, cursor
|
||||
/// or selection changes. Disallowing IME forgets the text. X11 ignores it.
|
||||
/// or selection changes; a call with the same text, cursor and anchor as the last one sends
|
||||
/// nothing. Disallowing IME forgets the text. X11 ignores it.
|
||||
fn set_ime_surrounding_text(&self, text: &str, cursor: usize, anchor: usize);
|
||||
/// The surrounding text to delete before inserting the [`Ime::Commit`] being handled.
|
||||
///
|
||||
|
||||
@@ -1066,6 +1066,14 @@ impl WindowState {
|
||||
pub fn set_ime_surrounding_text(&mut self, text: &str, cursor: usize, anchor: usize) {
|
||||
let (text, cursor, anchor) = surrounding_text_excerpt(text, cursor, anchor);
|
||||
let (cursor, anchor) = (cursor as i32, anchor as i32);
|
||||
// Each commit makes the compositor send `done`, and input-method-v2 compositors ignore
|
||||
// input-method commits made against an older serial, so an app calling this every frame
|
||||
// would lose typed text.
|
||||
let unchanged =
|
||||
|(t, c, a): &(String, i32, i32)| (t.as_str(), *c, *a) == (text, cursor, anchor);
|
||||
if self.ime_surrounding_text.as_ref().is_some_and(unchanged) {
|
||||
return;
|
||||
}
|
||||
if self.ime_allowed {
|
||||
for text_input in &self.text_inputs {
|
||||
text_input.set_surrounding_text(text.to_owned(), cursor, anchor);
|
||||
|
||||
@@ -170,6 +170,18 @@ fn wayland_surrounding_text_deletion_goes_with_a_commit() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wayland_unchanged_surrounding_text_sends_nothing() {
|
||||
// Each text-input commit makes the compositor send `done`, and input-method-v2 compositors
|
||||
// ignore input-method commits against an older serial, so an app that sets the surrounding
|
||||
// text every frame would lose typed text.
|
||||
let state = source("linux/wayland/window/state.rs");
|
||||
let set = section(&state, "pub fn set_ime_surrounding_text(", "\n }\n");
|
||||
let early_return = set.find("return;").expect("unchanged surrounding text is sent again");
|
||||
let commit = set.find("text_input.commit();").expect("surrounding text isn't committed");
|
||||
assert!(early_return < commit, "unchanged surrounding text is sent again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_reset_ime_cancels_the_composition() {
|
||||
// `CPS_CANCEL` discards the composition string; `CPS_COMPLETE` would commit it instead. The
|
||||
|
||||
Reference in new issue
Block a user