linux: Fix IME panel position while enumerating input methods (#12495)

Release Notes:

- N/A

This updates the IME position every time the selection changes, this is
probably only useful when you enumerate languages with your IME.

TODO:
- ~There is a rare chance that the ime panel is not updated because the
window input handler is None.~
- ~Update IME panel in vim mode.~
- ~Update IME panel when leaving Buffer search input.~

---------

Co-authored-by: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Fernando Tagawa 2024-08-28 23:58:40 -03:00 committed by GitHub
parent e6d5f4406f
commit 8e8927db4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 244 additions and 55 deletions

View file

@ -1120,6 +1120,13 @@ impl PlatformWindow for MacWindow {
None
}
fn update_ime_position(&self, _bounds: Bounds<Pixels>) {
unsafe {
let input_context: id = msg_send![class!(NSTextInputContext), currentInputContext];
let _: () = msg_send![input_context, invalidateCharacterCoordinates];
}
}
fn fps(&self) -> Option<f32> {
Some(self.0.lock().renderer.fps())
}
@ -1311,7 +1318,7 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
// enter it will still swallow certain keys (e.g. 'f', 'j') and not others
// (e.g. 'n'). This is a problem for certain kinds of views, like the terminal.
with_input_handler(this, |input_handler| {
if input_handler.selected_text_range().is_none() {
if input_handler.selected_text_range(false).is_none() {
handled = true;
input_handler.replace_text_in_range(None, &text)
}
@ -1683,10 +1690,12 @@ extern "C" fn marked_range(this: &Object, _: Sel) -> NSRange {
}
extern "C" fn selected_range(this: &Object, _: Sel) -> NSRange {
let selected_range_result =
with_input_handler(this, |input_handler| input_handler.selected_text_range()).flatten();
let selected_range_result = with_input_handler(this, |input_handler| {
input_handler.selected_text_range(false)
})
.flatten();
selected_range_result.map_or(NSRange::invalid(), |range| range.into())
selected_range_result.map_or(NSRange::invalid(), |selection| selection.range.into())
}
extern "C" fn first_rect_for_character_range(