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