mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 18:25:34 +01:00
Merge pull request #10108 from dotCooCoo/fix/type-editor-single-pass
Type: an edit runs each idle and typing frame once
This commit is contained in:
2 files changed
+22
-3
No files matched your search
@@ -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<usize> = (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<usize> = (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");
|
||||
}
|
||||
@@ -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<egui::Id> {
|
||||
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<egui::
|
||||
let target = app.session.tool_ime_target(view)?;
|
||||
let canvas_view = app.canvas_view()?;
|
||||
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, ui.ctx().clone()).id_salt(target).show(ui)).inner;
|
||||
let out = TypeEditor::new(app, caret, ui.ctx().clone()).id_salt(target).show_at(ui, caret);
|
||||
// Typing goes to the edit that starts, as a click on the part would take the keys.
|
||||
if out.unfocused_start {
|
||||
focus::request(ui.ctx(), FocusTarget::Id(out.response.id));
|
||||
|
||||
Reference in new issue
Block a user