From dfa52f919db0c30c82e021a8939dd21e23147eaa Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 23 Nov 2026 14:32:49 +0700 Subject: [PATCH] The Type tool's editor takes the keys back from its document canvas: the press that starts an edit focuses the canvas as its pass ends, after the editor asked for them, so the edit's typing and input-method text reached nothing --- crates/ui-egui/src/canvas.rs | 4 ++-- crates/ui-egui/src/type_editing.rs | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index b7b103290e..682c8ca66c 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -258,12 +258,12 @@ fn show_body(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace, pass: O crate::dialogs::dimension::floating(app, ui, space.view.rect); } let editing = app.session.tool_wants_text(); - crate::type_editing::show(app, ui); + crate::type_editing::show(app, ui, canvas_id(win)); out.reply = pass.map(|pass| tool_adapter::run(app, ui, pass)); // An edit the tool host started (a double-click on type) shows its editor in the same pass, so the keys of the // next frame are the edit's. if !editing { - crate::type_editing::show(app, ui); + crate::type_editing::show(app, ui, canvas_id(win)); } } drops::show(app, ui, win, kind); diff --git a/crates/ui-egui/src/type_editing.rs b/crates/ui-egui/src/type_editing.rs index 07d622bf3d..9ba78a557d 100644 --- a/crates/ui-egui/src/type_editing.rs +++ b/crates/ui-egui/src/type_editing.rs @@ -348,8 +348,8 @@ impl Component for TypeEditor<'_> { } /// Shows the editor part over the Type tool's caret while the tool edits text, before the tool host. A new edit target -/// is a new IME owner, so a reloaded document interrupts its composition. -pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) { +/// is a new IME owner, so a reloaded document interrupts its composition. `canvas` is the document canvas's id. +pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, canvas: egui::Id) { if !app.session.tool_wants_text() || app.viewport_hidden(ui.ctx()) { return; } @@ -359,8 +359,9 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) { let Some(canvas_view) = app.canvas_view() else { return }; let caret = Rect::from_two_pos(canvas_view.to_screen(a), canvas_view.to_screen(b)).expand2(egui::vec2(1.0, 0.0)); let out = ui.scope_builder(egui::UiBuilder::new().max_rect(caret), |ui| TypeEditor::new(app, caret).id_salt(target).show(ui)).inner; - // Typing goes to the edit that starts, as a click on the part would take the keys. - if out.unfocused_start { + // Typing goes to the edit that starts, as a click on the part would take the keys. The press that started it + // focuses the canvas as its pass ends, so the editor takes the keys back from its canvas in the next pass. + if out.unfocused_start || focus::has(ui.ctx(), canvas) { focus::request(ui.ctx(), FocusTarget::Id(out.response.id)); } }