Skip to content

Commit

Permalink
Make Ime::Preedit use tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov committed Apr 19, 2022
1 parent e15525f commit a4fb378
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,10 @@ pub enum Ime {
/// Notifies when a new composing text should be set at the cursor position.
///
/// The value represents a pair of the preedit string and the cursor begin position and end
/// position. When both indices are `None`, the cursor should be hidden.
/// position. When it's `None`, the cursor should be hidden.
///
/// The cursor position is byte-wise indexed.
Preedit(String, Option<usize>, Option<usize>),
Preedit(String, Option<(usize, usize)>),

/// Notifies when text should be inserted into the editor widget.
Commit(String),
Expand Down
6 changes: 5 additions & 1 deletion src/platform_impl/linux/wayland/seat/text_input/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ pub(super) fn handle_text_input(

// Push preedit string we've got after latest commit.
if let Some(preedit) = inner.pending_preedit.take() {
let event = Ime::Preedit(preedit.text, preedit.cursor_begin, preedit.cursor_end);
let cursor_range = preedit
.cursor_begin
.map(|b| (b, preedit.cursor_end.unwrap_or(b)));

let event = Ime::Preedit(preedit.text, cursor_range);
event_sink.push_window_event(WindowEvent::Ime(event), window_id);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,18 +1258,14 @@ impl<T: 'static> EventProcessor<T> {
self.composed_text = None;
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::Ime(Ime::Preedit("".to_owned(), None, None)),
event: WindowEvent::Ime(Ime::Preedit("".to_owned(), None)),
});
}
ImeEvent::Update(text, position) => {
if self.is_composing {
callback(Event::WindowEvent {
window_id: mkwid(window),
event: WindowEvent::Ime(Ime::Preedit(
text,
Some(position),
Some(position),
)),
event: WindowEvent::Ime(Ime::Preedit(text, Some((position, position)))),
});
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,7 @@ extern "C" fn set_marked_text(
window_id: WindowId(get_window_id(state.ns_window)),
event: WindowEvent::Ime(Ime::Preedit(
preedit_string,
Some(cursor_start),
Some(cursor_end),
Some((cursor_start, cursor_end)),
)),
}));
}
Expand All @@ -552,7 +551,7 @@ extern "C" fn unmark_text(this: &Object, _sel: Sel) {
let state = &mut *(state_ptr as *mut ViewState);
AppState::queue_event(EventWrapper::StaticEvent(Event::WindowEvent {
window_id: WindowId(get_window_id(state.ns_window)),
event: WindowEvent::Ime(Ime::Preedit(String::new(), Some(0), Some(0))),
event: WindowEvent::Ime(Ime::Preedit(String::new(), Some((0, 0)))),
}));
if state.is_ime_enabled() {
// Leave the Preedit state
Expand Down
5 changes: 3 additions & 2 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
if lparam == 0 {
userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: WindowEvent::Ime(Ime::Preedit(String::new(), None, None)),
event: WindowEvent::Ime(Ime::Preedit(String::new(), None)),
});
}

Expand All @@ -1146,10 +1146,11 @@ unsafe fn public_window_callback_inner<T: 'static>(
if (lparam as u32 & GCS_COMPSTR) != 0 {
if let Some((text, first, last)) = ime_context.get_composing_text_and_cursor() {
userdata.window_state.lock().ime_state = ImeState::Preedit;
let cursor_range = first.map(|f| (f, last.unwrap_or(f)));

userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: WindowEvent::Ime(Ime::Preedit(text, first, last)),
event: WindowEvent::Ime(Ime::Preedit(text, cursor_range)),
});
}
}
Expand Down

0 comments on commit a4fb378

Please sign in to comment.