From c101ffbcbeeefe223a2461c5dd990b7a9ec436c8 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 16 Nov 2026 21:10:15 +0000 Subject: [PATCH] IME engine: the input method's delete-surrounding reaches the editor owning the IME --- crates/behavior/src/editor.rs | 5 +++++ crates/ui-contract/src/runtime/egui/ime.rs | 8 ++++++++ crates/ui-contract/src/runtime/ime.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/crates/behavior/src/editor.rs b/crates/behavior/src/editor.rs index b32b39170..4c696ef76 100644 --- a/crates/behavior/src/editor.rs +++ b/crates/behavior/src/editor.rs @@ -62,6 +62,11 @@ impl EditorInput { EditorInput::Delete { forward, by } } + /// A `DeleteSurrounding` of `before` and `after` characters. + pub const fn delete_surrounding(before: usize, after: usize) -> Self { + EditorInput::DeleteSurrounding { before, after } + } + /// A `Preedit` of `text` with the IME's cursor. pub fn preedit(text: impl Into>, cursor: Option>) -> Self { EditorInput::Preedit { text: text.into(), cursor } diff --git a/crates/ui-contract/src/runtime/egui/ime.rs b/crates/ui-contract/src/runtime/egui/ime.rs index f20913283..26a2ddd59 100644 --- a/crates/ui-contract/src/runtime/egui/ime.rs +++ b/crates/ui-contract/src/runtime/egui/ime.rs @@ -10,6 +10,11 @@ pub(crate) enum Raw { cursor_chars: Option>, }, Commit(String), + /// The input method deletes characters around the caret or the marked text. + DeleteSurrounding { + before: usize, + after: usize, + }, /// The OS finished the reset with this request id. ResetCompleted(egui::ImeResetId), /// The integration dropped the reset request with this id; no completion follows. @@ -26,6 +31,9 @@ pub(crate) fn take_events(events: &mut Vec) -> Vec { taken.push(Raw::Preedit { text: text.clone(), cursor_chars: active_range_chars.clone() }) } ImeEvent::Commit(text) => taken.push(Raw::Commit(text.clone())), + ImeEvent::DeleteSurrounding { before_chars, after_chars } => { + taken.push(Raw::DeleteSurrounding { before: *before_chars, after: *after_chars }) + } _ => {} } false diff --git a/crates/ui-contract/src/runtime/ime.rs b/crates/ui-contract/src/runtime/ime.rs index d1fcfea14..6c845d5a6 100644 --- a/crates/ui-contract/src/runtime/ime.rs +++ b/crates/ui-contract/src/runtime/ime.rs @@ -124,6 +124,7 @@ pub(crate) fn begin(ctx: &Context, owner: Option) { engine.preedit = text.clone(); engine.edits.push(EditorInput::preedit(text, cursor)); } + os::Raw::DeleteSurrounding { before, after } => engine.edits.push(EditorInput::delete_surrounding(before, after)), os::Raw::Commit(text) => { engine.composing = false; engine.preedit.clear();