diff --git a/crates/engine/src/cmd/comment.rs b/crates/engine/src/cmd/comment.rs index 35ea38901..87c9cfe9d 100644 --- a/crates/engine/src/cmd/comment.rs +++ b/crates/engine/src/cmd/comment.rs @@ -874,8 +874,8 @@ pub fn specs() -> Vec { let v = &mut s.ds_mut()?.view; let zoom = v.zoom; v.fit(r, crate::ViewState::MAX_ZOOM); - // Pins at one spot: at least double the zoom so they come apart. - if v.zoom < zoom * 2.0 { + // A single pin position has no span to fit, so double the previous zoom. + if r.width() == 0.0 && r.height() == 0.0 && v.zoom < zoom * 2.0 { v.set_zoom_at(zoom * 2.0, (v.cx, v.cy)); } Ok(json!({"zoom": v.zoom})) diff --git a/crates/engine/src/comments_polish_tests.rs b/crates/engine/src/comments_polish_tests.rs index c6690ce4a..9fb0bf736 100644 --- a/crates/engine/src/comments_polish_tests.rs +++ b/crates/engine/src/comments_polish_tests.rs @@ -273,6 +273,21 @@ fn links_open_and_zoom_to_a_thread() { assert!(s.execute("comment.zoom", &json!({"ids": [12345]})).is_err()); } +#[test] +fn zoom_to_spread_out_comments_keeps_both_pins_in_view() { + let mut s = Session::new(); + let a = add(&mut s, 0.0, 0.0, "Left", "Sam"); + let b = add(&mut s, 800.0, 0.0, "Right", "Sam"); + s.execute("view.set", &json!({"zoom": 1, "cx": 400, "cy": 0, "vw": 1200, "vh": 800})).unwrap(); + + s.execute("comment.zoom", &json!({"ids": [a, b]})).unwrap(); + + let v = &s.ds().unwrap().view; + let (left, _) = v.origin(); + let right = left + v.vw / v.zoom; + assert!(left <= 0.0 && right >= 800.0, "both pins should fit in the visible range {left}..{right}"); +} + #[test] fn next_steps_through_the_list_across_pages() { let mut s = Session::new();