Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions winit-appkit/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,20 @@ define_class!(

// Commit only if we have marked text.
if self.hasMarkedText() && self.is_ime_enabled() && !is_control {
// Clear marked text as required by the NSTextInputClient protocol.
// This prevents subsequent insertText calls (e.g., for a trailing
// space) from incorrectly seeing stale marked text.
*self.ivars().marked_text.borrow_mut() = NSMutableAttributedString::new();

self.queue_event(WindowEvent::Ime(Ime::Preedit(String::new(), None)));
self.queue_event(WindowEvent::Ime(Ime::Commit(string)));
self.ivars().ime_state.set(ImeState::Committed);
} else if self.ivars().ime_state.get() == ImeState::Committed && !is_control {
// After committing composed text (e.g., Korean "ν•œ"), the IME may
// send a second insertText for the triggering character (e.g.,
// space). Forward it to the app as a regular key event instead of
// committing it again through IME, which would cause double input.
self.ivars().forward_key_to_app.set(true);
}
}

Expand All @@ -404,14 +415,6 @@ define_class!(
fn do_command_by_selector(&self, command: Sel) {
trace_scope!("doCommandBySelector:");

// We shouldn't forward any character from just committed text, since we'll end up
// sending it twice with some IMEs like Korean one. We'll also always send
// `Enter` in that case, which is not desired given it was used to confirm
// IME input.
if self.ivars().ime_state.get() == ImeState::Committed {
return;
}

self.ivars().forward_key_to_app.set(true);

if self.hasMarkedText() && self.ivars().ime_state.get() == ImeState::Preedit {
Expand Down
1 change: 1 addition & 0 deletions winit/src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ changelog entry.
- On X11, fix `set_hittest` not working on some window managers.
- On Redox, handle `EINTR` when reading from `event_socket` instead of panicking.
- On Wayland, switch from using the `ahash` hashing algorithm to `foldhash`.
- On macOS, fix double space input and key loss when committing Korean IME composition.