mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
IME engine: the input method's delete-surrounding reaches the editor owning the IME
This commit is contained in:
@@ -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<Arc<str>>, cursor: Option<Range<usize>>) -> Self {
|
||||
EditorInput::Preedit { text: text.into(), cursor }
|
||||
|
||||
@@ -10,6 +10,11 @@ pub(crate) enum Raw {
|
||||
cursor_chars: Option<std::ops::Range<usize>>,
|
||||
},
|
||||
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<Event>) -> Vec<Raw> {
|
||||
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
|
||||
|
||||
@@ -124,6 +124,7 @@ pub(crate) fn begin(ctx: &Context, owner: Option<Id>) {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user