Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add IME support #762

Merged
merged 14 commits into from
Nov 30, 2024
11 changes: 10 additions & 1 deletion masonry/src/passes/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ use crate::passes::{enter_span, enter_span_if, merge_state_up, recurse_on_childr
use crate::render_root::{RenderRoot, RenderRootSignal, RenderRootState};
use crate::tree_arena::ArenaMut;
use crate::{
PointerEvent, QueryCtx, RegisterCtx, Update, UpdateCtx, Widget, WidgetId, WidgetState,
PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
WidgetState,
};

use super::event::run_on_text_event_pass;

// --- MARK: HELPERS ---
fn get_id_path(root: &RenderRoot, widget_id: Option<WidgetId>) -> Vec<WidgetId> {
let Some(widget_id) = widget_id else {
Expand Down Expand Up @@ -471,6 +474,12 @@ pub(crate) fn run_update_focus_pass(root: &mut RenderRoot) {
// We also request accessibility, because build_access_node() depends on the focus state.
if let Some(prev_focused) = prev_focused {
if root.widget_arena.has(prev_focused) {
if was_ime_active {
// IME was active, but the next focused widget is going to receive the
// Ime::Disabled event. Synthesize an Ime::Disabled event here and send it to
// the widget about to be unfocused.
run_on_text_event_pass(root, &TextEvent::Ime(winit::event::Ime::Disabled));
}
tomcur marked this conversation as resolved.
Show resolved Hide resolved
run_single_update_pass(root, prev_focused, |widget, ctx| {
widget.update(ctx, &Update::FocusChanged(false));
ctx.widget_state.request_accessibility = true;
Expand Down
13 changes: 2 additions & 11 deletions masonry/src/widget/text_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,17 +788,8 @@ impl<const EDITABLE: bool> Widget for TextArea<EDITABLE> {

fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::FocusChanged(focused) => {
// HACK: currently, when moving focus away from a text area, the Ime::Disabled
// event is routed to the newly focused widget. Do IME clean up here.
if !focused && self.editor.is_composing() {
let (fctx, lctx) = ctx.text_contexts();
self.editor.transact(fctx, lctx, |txn| txn.clear_compose());
self.rendered_generation = self.editor.generation();
ctx.request_layout();
} else {
ctx.request_render();
}
Update::FocusChanged(_) => {
ctx.request_render();
}
Update::DisabledChanged(_) => {
// We might need to use the disabled brush, and stop displaying the selection.
Expand Down