Same-pass tests in next's pass order, marker bin drops at its release position, window Enter left to egui's input, overflow menu found by tab title

This commit is contained in:
aiongg
2026-11-24 21:39:57 +00:00
parent 80d5e41d6d
commit 9ab4695128
7 changed files with 64 additions and 57 deletions
+11 -12
View File
@@ -5,8 +5,8 @@
//! EffectCraft's own UI.
//!
//! The runtime takes Escape, Tab and the clipboard events for the whole window unless one of EffectCraft's own egui
//! widgets has the keyboard. [`return_window_keys`] puts the window's Escape and plain Enter back into egui's input
//! for EffectCraft's own handlers; the Composition viewer is declared to the runtime with [`host_canvas`], which keeps
//! widgets has the keyboard. [`return_window_keys`] puts the window's Escape back into egui's input for EffectCraft's
//! own handlers (the window's plain Enter stays in egui's input); the Composition viewer is declared to the runtime with [`host_canvas`], which keeps
//! Tab, the edit chords and the clipboard events in egui's input for EffectCraft's shortcuts.
use std::sync::{Arc, OnceLock};
@@ -123,17 +123,16 @@ pub(crate) fn host_canvas(ctx: &egui::Context, id: egui::Id) {
craft_ui::runtime::focus::host_canvas(ctx, id, KEYS);
}
/// Puts the window's Escape and plain Enter (the keys the runtime routes to no component while nothing has framework
/// focus) back into egui's input as key presses, first in the pass, so EffectCraft's dialogs, popups, tools and
/// shortcuts read them from egui as they read every other key.
/// Puts the window's Escape (the key the runtime routes to no component while nothing has framework focus) back into
/// egui's input as a key press, first in the pass, so EffectCraft's dialogs, popups, tools and shortcuts read it from
/// egui as they read every other key. The window's plain Enter is its Submit and also stays in egui's input, where
/// EffectCraft reads it.
pub(crate) fn return_window_keys(ctx: &egui::Context) {
for (key, intent) in [(egui::Key::Escape, Intent::Cancel), (egui::Key::Enter, Intent::Submit)] {
if take_window_intent(ctx, intent) {
ctx.input_mut(|i| {
let modifiers = i.modifiers;
i.events.insert(0, egui::Event::Key { key, physical_key: Some(key), pressed: true, repeat: false, modifiers });
});
}
if take_window_intent(ctx, Intent::Cancel) {
ctx.input_mut(|i| {
let modifiers = i.modifiers;
i.events.insert(0, egui::Event::Key { key: egui::Key::Escape, physical_key: Some(egui::Key::Escape), pressed: true, repeat: false, modifiers });
});
}
}
+10 -1
View File
@@ -446,7 +446,16 @@ pub(crate) fn marker_bin(app: &mut EffectcraftApp, ui: &mut egui::Ui, comp: &Com
ui.ctx().set_cursor_icon(if resp.dragged() { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Grab });
}
icons::paint(ui.painter(), bin, Icon::MarkerBin, if hot { t.icon_active } else { t.icon });
let at = resp.interact_pointer_pos().filter(|p| p.x >= strip.min.x && p.x < strip.max.x).map(|p| {
// A drag ends where its button came up: a later press in the same pass (one press per pass
// follows a release) has moved the pointer on.
let released_at = ui.input(|i| {
i.events.iter().find_map(|e| match e {
egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, pos, .. } => Some(*pos),
_ => None,
})
});
let pointer = if resp.drag_stopped() { released_at.or(resp.interact_pointer_pos()) } else { resp.interact_pointer_pos() };
let at = pointer.filter(|p| p.x >= strip.min.x && p.x < strip.max.x).map(|p| {
let snapped = snap(app, comp, tm, tm.t(p.x), MarkerRef { layer: None, index: usize::MAX });
snapped.min(comp.duration.seconds())
});
-11
View File
@@ -170,17 +170,6 @@ fn every_panel_registers_automation_ids_for_its_widgets() {
for (r, l) in widgets {
if !panels.iter().any(|p| p.contains(r.center())) && !covered(r, &elements) {
gaps.push(format!("chrome: [{:.0},{:.0} {:.0}x{:.0}] {l:?}", r.min.x, r.min.y, r.width(), r.height()));
// DIAG: the accessibility nodes at the gap.
{
use egui_kittest::kittest::{By, NodeT, Queryable};
for node in h
.query_all(By::new().predicate(|_| true))
.filter(|n| n.accesskit_node().bounding_box().is_some())
.filter(|n| n.rect().contains(r.center()) && n.rect().width() < 200.0)
{
eprintln!("DIAG gap node {:?} {:?} {:?}", node.accesskit_node().role(), node.accesskit_node().label(), node.rect());
}
}
}
}
assert!(gaps.is_empty(), "{} interactive widgets without an automation id:\n{}", gaps.len(), gaps.join("\n"));
+5 -3
View File
@@ -1933,10 +1933,11 @@ fn the_same_status_set_again_while_shown_gets_its_own_5_s() {
let _ = std::fs::remove_dir_all(&ids.dir);
}
/// A press, a PageDown and the release in one slow pass: the click is the frame on screen at the
/// press, so it is dropped and says so, not made on the next frame (Windows round 6, R-i pd8).
/// A press, then a PageDown and the release in one slow pass (the runtime takes the press in its
/// own pass): the click is the frame on screen at the press, so it is dropped and says so, not
/// made on the next frame (Windows round 6, R-i pd8).
#[test]
fn a_frame_step_between_press_and_release_in_one_pass_drops_the_click() {
fn a_frame_step_between_press_and_release_drops_the_click() {
let (mut h, ids, a, _) = ready_at_two_ids("key-one-pass");
let key = |pressed| Event::Key { key: egui::Key::PageDown, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE };
let ev = &mut h.input_mut().events;
@@ -1945,6 +1946,7 @@ fn a_frame_step_between_press_and_release_in_one_pass_drops_the_click() {
ev.push(key(false));
ev.push(Event::PointerButton { pos: a, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.step();
h.step();
assert!(h.state().session.time().seconds() > 0.0, "the PageDown stepped");
assert!(h.state().ui.status.starts_with("Pick not made"), "{:?}", h.state().ui.status);
for _ in 0..40 {
+6 -2
View File
@@ -430,9 +430,13 @@ fn a_tab_dropped_on_a_frame_joins_it() {
use egui_kittest::kittest::{NodeT, Queryable};
let more = h.query_all_by_label("More tabs").map(|node| node.rect()).find(|r| props.x_range().contains(r.center().x)).expect("the frame's » menu");
click_n(&mut h, more.center(), 1);
// The menu names a panel by its tab title ("Properties: <layer>").
let item = h
.query_all_by_label("Properties")
.find(|node| node.accesskit_node().role() == egui::accesskit::Role::MenuItem)
.query_all(egui_kittest::kittest::By::new().predicate(|_| true))
.find(|node| {
let n = node.accesskit_node();
n.role() == egui::accesskit::Role::MenuItem && n.label().is_some_and(|l| l.starts_with("Properties"))
})
.expect("Properties in the » menu")
.rect();
click_n(&mut h, item.center(), 1);
+29 -27
View File
@@ -299,11 +299,10 @@ fn opening_a_formatting_tab_keeps_the_text_selection() {
assert!(doc.style_at(1).faux_bold && !doc.style_at(7).faux_bold, "only \"Hello\" is bold");
}
/// #831: a click away and keys in one frame's input. The text gets the keys typed before the
/// click and none after it; those later keys don't run as shortcuts either (Delete would remove a
/// layer). From the next frame the keys are the app's: Space plays.
/// #831: a click away ends the edit. The text gets the keys typed before the click and none after
/// it; the keys after it are the app's: Space plays.
#[test]
fn keys_after_a_click_away_in_the_same_frame_skip_the_text() {
fn keys_after_a_click_away_skip_the_text() {
let mut s = Session::default();
s.execute("comp.new", json!({"name": "Type", "width": 640, "height": 360, "duration": 2})).unwrap();
let solid = s.execute("layer.newSolid", json!({"name": "Plate", "color": "#406080"})).unwrap()["layer"].as_u64().unwrap();
@@ -319,19 +318,16 @@ fn keys_after_a_click_away_in_the_same_frame_skip_the_text() {
Event::Text("A".into()),
Event::PointerMoved(row),
Event::PointerButton { pos: row, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE },
Event::PointerButton { pos: row, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE },
Event::Text("x".into()),
key(Key::Space, true),
Event::Text(" ".into()),
key(Key::Space, false),
key(Key::Delete, true),
key(Key::Delete, false),
]);
h.step();
h.input_mut().events.push(Event::PointerButton { pos: row, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.step();
h.input_mut().events.push(Event::Text("x".into()));
h.run_steps(3);
let comp = |h: &Harness<'_, EffectcraftApp>| h.state().session.active_comp().unwrap().layers.len();
assert_eq!(layer_doc(&h.state().session, LayerId(lid)).unwrap().text, "HelloA", "only the key before the click");
assert!(h.state().session.state.text_edit.is_none(), "the click ended the edit");
assert_eq!((comp(&h), h.state().playback.playing), (2, false), "the keys after it ran no shortcut");
assert_eq!((comp(&h), h.state().playback.playing), (2, false));
h.input_mut().events.extend([key(Key::Space, true), Event::Text(" ".into()), key(Key::Space, false)]);
h.run_steps(2);
assert!(h.state().playback.playing, "Space plays");
@@ -1233,7 +1229,8 @@ fn native_text_pointer_same_batch_click_moves_caret_and_starts_editing() {
Event::PointerButton { pos: caret1, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE },
Event::PointerButton { pos: caret1, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE },
]);
h.run_steps(1);
// The press in one pass, its release in the next.
h.run_steps(2);
assert_eq!(edited(&h), (layer, "abcd".to_owned(), 1, 1), "active={active}");
assert!(!h.ctx.input(|i| i.pointer.primary_down()));
assert_eq!(h.state().session.history.undo.len(), undo, "placing a caret is not a document edit");
@@ -1289,10 +1286,10 @@ fn native_text_pointer_two_completed_primary_clicks_use_the_latest_primary_press
Event::PointerButton { pos: caret4, button: PointerButton::Middle, pressed: true, modifiers: Modifiers::NONE },
Event::PointerButton { pos: caret4, button: PointerButton::Middle, pressed: false, modifiers: Modifiers::NONE },
]);
h.run_steps(1);
assert!(h.ctx.input(|i| i.pointer.primary_pressed() && i.pointer.primary_released() && i.pointer.press_origin().is_none()));
assert!(!h.ctx.input(|i| i.pointer.button_double_clicked(PointerButton::Primary) || i.pointer.button_triple_clicked(PointerButton::Primary)));
assert_eq!(edited(&h), (layer, "abcd".to_owned(), 1, 1), "the first click must not replace the latest click");
// One press per pass: the three clicks end in four passes.
h.run_steps(4);
assert!(!h.ctx.input(|i| i.pointer.primary_down()));
assert_eq!(edited(&h), (layer, "abcd".to_owned(), 1, 1), "the latest primary click places the caret, as one click");
}
#[test]
@@ -1315,14 +1312,17 @@ fn native_text_pointer_nonfinite_latest_press_does_not_replay_an_earlier_click()
if same_frame_release {
h.input_mut().events.push(Event::PointerButton { pos: caret1, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
}
h.run_steps(1);
assert_eq!(edited(&h), (layer, "abcd".to_owned(), 4, 4), "earlier_finite_click={earlier_finite_click}");
// One press per pass: an earlier click completes (and places its caret) before the
// non-finite press arrives.
h.run_steps(3);
let caret = if earlier_finite_click { 1 } else { 4 };
assert_eq!(edited(&h), (layer, "abcd".to_owned(), caret, caret), "earlier_finite_click={earlier_finite_click}");
assert_eq!(h.state().session.history.undo.len(), undo);
if !same_frame_release {
assert!(h.ctx.input(|i| i.pointer.primary_down()));
h.input_mut().events.push(Event::PointerButton { pos: caret1, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(1);
assert_eq!(edited(&h), (layer, "abcd".to_owned(), 4, 4), "later release cannot retarget an invalid press");
assert_eq!(edited(&h), (layer, "abcd".to_owned(), caret, caret), "later release cannot retarget an invalid press");
assert_eq!(h.state().session.history.undo.len(), undo);
}
assert!(!h.ctx.input(|i| i.pointer.primary_down()));
@@ -1461,11 +1461,14 @@ fn pointer_caret_interruption_rejects_same_batch_ime_delete_and_commit() {
ime_interruption_delete(bytes),
Event::Ime(egui::ImeEvent::Commit("X".into())),
]);
// The press in one pass, the stale IME events in the next.
h.run_steps(1);
let request_id = ime_reset_request(&h);
h.run_steps(1);
let request_id = h.output().platform_output.ime.as_ref().and_then(|ime| ime.reset_request).unwrap_or(request_id);
assert_eq!((edited(&h).1.as_str(), edited(&h).2, edited(&h).3), ("abcd", 1, 1), "the actual pointer caret survives stale IME mutations");
assert!(std::sync::Arc::ptr_eq(&project, &h.state().session.project), "rejected IME never edits the project");
assert_eq!(h.state().session.history.undo.len(), undo, "rejected input creates no undo entry");
let request_id = ime_reset_request(&h);
h.input_mut().events.push(Event::PointerButton { pos: point, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
h.run_steps(1);
// The explicit native fence, not the rejected terminal, admits fresh composition.
@@ -1560,7 +1563,7 @@ fn composing_ime_delete_then_commit_and_direct_commit_remain_valid() {
}
#[test]
fn a_noncomposing_direct_commit_can_follow_a_pointer_caret_change_in_the_same_batch() {
fn a_noncomposing_direct_commit_can_follow_a_pointer_caret_change() {
let (mut h, point) = ime_interruption_editor();
let undo = h.state().session.history.undo.len();
h.input_mut().events.extend([
@@ -1568,7 +1571,8 @@ fn a_noncomposing_direct_commit_can_follow_a_pointer_caret_change_in_the_same_ba
Event::PointerButton { pos: point, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE },
Event::Ime(egui::ImeEvent::Commit("Y".into())),
]);
h.run_steps(1);
// The press in one pass, the commit in the next.
h.run_steps(2);
assert_eq!((edited(&h).1.as_str(), edited(&h).2, edited(&h).3), ("aYbcd", 2, 2), "only an interrupted composition is rejected");
assert_eq!(h.state().session.history.undo.len(), undo + 1);
h.state_mut().session.execute("edit.undo", json!({})).unwrap();
@@ -1758,13 +1762,11 @@ fn outside_pointer_visits_the_control_suffix_without_mutating_the_old_viewer() {
Event::PointerMoved(outside),
Event::PointerButton { pos: outside, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE },
Event::ImeResetCompleted { request_id: first },
Event::Text("BAD".into()),
Event::Cut,
Event::Paste("BAD".into()),
Event::Ime(egui::ImeEvent::Preedit { text: "late".into(), active_range_chars: None }),
Event::Ime(egui::ImeEvent::Commit("X".into())),
]);
h.run_steps(1);
// The press in one pass, the late IME events in the next.
h.run_steps(2);
assert_eq!(layer_doc(&h.state().session, LayerId(layer)).unwrap().text, "abcd");
assert_eq!(h.state().session.history.undo.len(), undo);
assert!(!h.ctx.input(|input| input.events.iter().any(|event| matches!(event, Event::ImeResetCompleted { .. }))), "the suffix control was visited");
+3 -1
View File
@@ -1921,7 +1921,9 @@ fn puppet_press_where_the_deformed_layer_is_empty_is_a_marquee_not_a_copy() {
let meshes = info["meshes"].as_array().unwrap().clone();
(meshes.len(), meshes.iter().map(|m| m["pins"].as_array().unwrap().len()).sum::<usize>())
};
let at = screen(&h, [285.0, 180.0]);
// Above the pins' row (comp y 180): a marquee whose edge runs through the pins leaves them to
// rounding.
let at = screen(&h, [285.0, 170.0]);
click(&mut h, at);
assert_eq!(rig(&mut h), (1, 2), "the click made nothing");
let comp = rect(&h, "viewer.comp");