trim/extend: exercise the Shift cache key at Crossing with a steady prompt

This commit is contained in:
kc8a
2026-11-30 22:14:28 +00:00
parent c9277f90e0
commit 65fbabbbee
+11 -4
View File
@@ -542,10 +542,11 @@ fn a_fence_point_taken_back_with_undo_updates_the_highlight_at_once() {
painted_text(&mut app, &ctx, below);
assert!(app.canvas.hover_part.list.as_ref().is_none_or(|l| l.prims.is_empty()), "nothing is crossed");
}
/// #1118: holding Shift at TRIM's prompt flips the cached rollover highlight to the opposite
/// edit and back, recomputing it even though the cursor has not moved.
/// #1118: at TRIM's Crossing stage the prompt does not change with Shift, so holding Shift flips
/// the cached highlight to the opposite edit and back only through the `session.shift_down` cache bit.
/// The cursor stays fixed; only `shift_down` changes across the frames below.
#[test]
fn trim_shift_flips_the_cached_highlight_without_moving_the_cursor() {
fn trim_shift_flips_the_cached_crossing_highlight_with_a_steady_prompt() {
let mut app = CadApp::new(cadcraft_engine::Session::new(), crate::Services::default());
for points in [[[4, -5], [4, 5]], [[10, -5], [10, 5]], [[0, 0], [8, 0]]] {
app.run("line", serde_json::json!({ "points": points })).unwrap();
@@ -555,20 +556,26 @@ fn trim_shift_flips_the_cached_highlight_without_moving_the_cursor() {
crate::framework::install_headless(&ctx);
painted_text(&mut app, &ctx, pos2(700.0, 450.0));
app.session.cmdline("trim").unwrap();
let cursor = app.canvas.xf.unwrap().to_screen(Vec2::new(6.0, 0.0));
app.session.input(Input::Keyword("Crossing".into())).unwrap();
app.session.input(Input::Point(Vec2::new(4.5, -1.0))).unwrap();
let cursor = app.canvas.xf.unwrap().to_screen(Vec2::new(6.0, 1.0));
painted_text(&mut app, &ctx, cursor);
let prompt = app.session.prompt_text();
assert_eq!(prompt, "TRIM Specify opposite corner:", "the Crossing prompt is steady under Shift");
let part = app.canvas.hover_part.list.as_ref().expect("a part of the line is highlighted");
assert!((part.bounds.min.x - 4.0).abs() < 1e-6 && (part.bounds.max.x - 8.0).abs() < 1e-6, "the piece a click removes: {:?}", part.bounds);
let (hover, cursor, scale) = (app.canvas.hover, app.canvas.cursor, app.canvas.xf.unwrap().scale);
let computed = app.canvas.hover_part.list_gen;
app.session.shift_down = true;
app.canvas.hover_part.update(&app.session, hover, cursor, scale);
assert_eq!(app.session.prompt_text(), prompt, "the prompt is unchanged by Shift at Crossing");
assert_ne!(app.canvas.hover_part.list_gen, computed, "shift recomputes the highlight at a resting cursor");
let part = app.canvas.hover_part.list.as_ref().expect("the opposite part is highlighted");
assert!((part.bounds.min.x - 8.0).abs() < 1e-6 && (part.bounds.max.x - 10.0).abs() < 1e-6, "the stretch a shift-click adds: {:?}", part.bounds);
let flipped = app.canvas.hover_part.list_gen;
app.session.shift_down = false;
app.canvas.hover_part.update(&app.session, hover, cursor, scale);
assert_eq!(app.session.prompt_text(), prompt, "releasing Shift keeps the Crossing prompt");
assert_ne!(app.canvas.hover_part.list_gen, flipped, "releasing shift recomputes it again");
let part = app.canvas.hover_part.list.as_ref().expect("the original part is highlighted");
assert!((part.bounds.min.x - 4.0).abs() < 1e-6 && (part.bounds.max.x - 8.0).abs() < 1e-6, "back to the trim piece: {:?}", part.bounds);