mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-29 01:34:37 +01:00
Merge pull request #2549 from MMexicann/patch-16
Keep comment pins in view when zooming to them
This commit is contained in:
2 files changed
+17
-2
No files matched your search
@@ -874,8 +874,8 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
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}))
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user