From a978fd242a56161482bcc533e5aae8baa97fc426 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 10:16:00 -0800 Subject: [PATCH] Type: an edit runs each idle and typing frame once The Type tool's text part was shown in the canvas's flow, in a scope sized to the caret. While the tool edited text, every other frame ran its UI twice: the frame's layout check found the part changed and the frame was run again. The part is now shown at the caret's rect with no allocation, as the canvas's other overlays are, and each idle and typing frame runs once. --- crates/ui-egui/src/tests/lifecycle.rs | 19 +++++++++++++++++++ crates/ui-egui/src/type_editing.rs | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/tests/lifecycle.rs b/crates/ui-egui/src/tests/lifecycle.rs index 41ace0ff2d..4080427be8 100644 --- a/crates/ui-egui/src/tests/lifecycle.rs +++ b/crates/ui-egui/src/tests/lifecycle.rs @@ -245,3 +245,22 @@ fn ime_delete_surrounding_then_commit_edit_the_type_tool_once_in_order() { ime_frame(&mut app, &ctx, vec![Event::Ime(egui::ImeEvent::Commit("Q".into()))], |_| {}); assert_eq!(plain(&app, id), "abcQZ"); } + +/// While the Type tool edits text, each idle frame and each typing frame runs its UI once: the text part measures the +/// same in the measuring run and the real run, so no frame is discarded and run again. +#[test] +fn an_edit_runs_each_idle_and_typing_frame_once() { + let (mut app, id) = app_with_text("abc"); + let ctx = crate::testing::ui_context(); + ime_frame(&mut app, &ctx, vec![], |_| {}); + ime_frame(&mut app, &ctx, vec![], |_| {}); + begin_typing(&mut app, &ctx, id); + for _ in 0..3 { + ime_frame(&mut app, &ctx, vec![], |_| {}); + } + let idle: Vec = (0..6).map(|_| run_frame(&mut app, &ctx, vec![], |_| {}, false).0).collect(); + assert_eq!(idle, [1; 6], "each idle frame of the edit runs one pass"); + let typing: Vec = (0..6).map(|_| run_frame(&mut app, &ctx, vec![Event::Text("x".into())], |_| {}, false).0).collect(); + assert_eq!(typing, [1; 6], "each typing frame runs one pass"); + assert!(plain(&app, id).contains("xxxxxx"), "every frame's typing reached the text"); +} diff --git a/crates/ui-egui/src/type_editing.rs b/crates/ui-egui/src/type_editing.rs index 8ee26749a2..878d1d757e 100644 --- a/crates/ui-egui/src/type_editing.rs +++ b/crates/ui-egui/src/type_editing.rs @@ -486,7 +486,8 @@ impl Component for TypeEditor<'_> { } /// Shows the editor part over the Type tool's caret while the tool edits text, before the tool host; returns the part's -/// id. A new edit target is a new IME owner, so a reloaded document interrupts its composition. +/// id. A new edit target is a new IME owner, so a reloaded document interrupts its composition. The part is shown at +/// the caret's rect and takes no room in the canvas's flow, as the canvas's other overlays are. pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) -> Option { if !app.session.tool_wants_text() || app.viewport_hidden(ui.ctx()) { return None; @@ -496,8 +497,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) -> Option