mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
fix(macOS) "fix" toggling IME on appkit backend (#4512)
Co-authored-by: Random-Scientist <Random-Scientist@users.noreply.github.com>
This commit is contained in:
@@ -872,24 +872,33 @@ impl WinitView {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub(super) fn enable_ime(&self, capabilities: ImeCapabilities) {
|
||||||
|
// This seems reasonable but the prior behavior of `set_ime_allowed` doesn't do this
|
||||||
|
// (it was also broken but let's not break things worse)
|
||||||
|
|
||||||
pub(super) fn set_ime_allowed(&self, capabilities: Option<ImeCapabilities>) {
|
// if self.ivars().ime_capabilities.get().is_none() {
|
||||||
if self.ivars().ime_capabilities.get().is_some() {
|
// self.ivars().ime_state.set(ImeState::Ground);
|
||||||
return;
|
// }
|
||||||
}
|
|
||||||
self.ivars().ime_capabilities.set(capabilities);
|
|
||||||
|
|
||||||
if capabilities.is_some() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear markedText
|
|
||||||
*self.ivars().marked_text.borrow_mut() = NSMutableAttributedString::new();
|
|
||||||
|
|
||||||
|
// why are we disabling things in an enable fn? who knows. it's what the previous one did
|
||||||
|
// though
|
||||||
if self.ivars().ime_state.get() != ImeState::Disabled {
|
if self.ivars().ime_state.get() != ImeState::Disabled {
|
||||||
self.ivars().ime_state.set(ImeState::Disabled);
|
self.ivars().ime_state.set(ImeState::Disabled);
|
||||||
self.queue_event(WindowEvent::Ime(Ime::Disabled));
|
self.queue_event(WindowEvent::Ime(Ime::Disabled));
|
||||||
}
|
}
|
||||||
|
self.ivars().ime_capabilities.set(Some(capabilities));
|
||||||
|
*self.ivars().marked_text.borrow_mut() = NSMutableAttributedString::new();
|
||||||
|
}
|
||||||
|
pub(super) fn disable_ime(&self) {
|
||||||
|
// see above
|
||||||
|
self.ivars().ime_capabilities.set(None);
|
||||||
|
if self.ivars().ime_state.get() != ImeState::Disabled {
|
||||||
|
self.ivars().ime_state.set(ImeState::Disabled);
|
||||||
|
self.queue_event(WindowEvent::Ime(Ime::Disabled));
|
||||||
|
}
|
||||||
|
// we probably don't need to do this, but again this mirrors the prior behavior of
|
||||||
|
// `set_ime_allowed`
|
||||||
|
*self.ivars().marked_text.borrow_mut() = NSMutableAttributedString::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn ime_capabilities(&self) -> Option<ImeCapabilities> {
|
pub(super) fn ime_capabilities(&self) -> Option<ImeCapabilities> {
|
||||||
|
|||||||
@@ -1686,7 +1686,7 @@ impl WindowDelegate {
|
|||||||
if current_caps.is_some() {
|
if current_caps.is_some() {
|
||||||
return Err(ImeRequestError::AlreadyEnabled);
|
return Err(ImeRequestError::AlreadyEnabled);
|
||||||
}
|
}
|
||||||
self.view().set_ime_allowed(Some(capabilities));
|
self.view().enable_ime(capabilities);
|
||||||
request_data
|
request_data
|
||||||
},
|
},
|
||||||
ImeRequest::Update(request_data) => {
|
ImeRequest::Update(request_data) => {
|
||||||
@@ -1696,7 +1696,7 @@ impl WindowDelegate {
|
|||||||
request_data
|
request_data
|
||||||
},
|
},
|
||||||
ImeRequest::Disable => {
|
ImeRequest::Disable => {
|
||||||
self.view().set_ime_allowed(None);
|
self.view().disable_ime();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -58,3 +58,4 @@ changelog entry.
|
|||||||
- On Windows, fix `WM_IME_SETCONTEXT` IME UI flag masking on `lParam`.
|
- On Windows, fix `WM_IME_SETCONTEXT` IME UI flag masking on `lParam`.
|
||||||
- On macOS, fix crash in `set_marked_text` when native Pinyin IME sends out-of-bounds `selected_range`.
|
- On macOS, fix crash in `set_marked_text` when native Pinyin IME sends out-of-bounds `selected_range`.
|
||||||
- On X11, fix debug mode overflow panic in `set_timestamp`.
|
- On X11, fix debug mode overflow panic in `set_timestamp`.
|
||||||
|
- On macOS, fix IME being locked on (regardless of requests to disable) after being enabled once.
|
||||||
Reference in New Issue
Block a user