mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-31 21:27:00 -06:00
Guides: a ruler guide shows while dragged with Real-time Drawing off (#4646)
With Preferences > Performance > Real-time Drawing and Editing off, tool previews are deferred to the release, so a guide dragged out of a ruler (guide.add) or moved with a selection tool (guide.move) showed only its position label until the button was released. Guide previews now always apply as the guide is dragged: the guide is all such a drag shows. #4646's units and guides lost on reopen don't reproduce for a native file: a new millimetre document's ruler guides and units survive Save, Close and Open in .vectorcraft, PDF, .ai and EPS (new regression test, and live in the app with Background Save). An SVG saved without Preserve Editing reopens in pixels with no guides, as the reporter saw.
This commit is contained in:
@@ -1616,6 +1616,23 @@ fn real_time_drawing_off_skips_tool_previews_until_commit() {
|
||||
assert!(s.doc().unwrap().revision > rev, "on again: previews run while dragging");
|
||||
}
|
||||
|
||||
/// #4646: with Real-time Drawing off, a ruler guide moved with the Selection tool still moves
|
||||
/// while it is dragged (the guide is all the drag shows).
|
||||
#[test]
|
||||
fn real_time_drawing_off_still_shows_a_dragged_guide() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap();
|
||||
s.execute("guide.add", &json!({"vertical": true, "pos": 100})).unwrap();
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("selection", v).unwrap();
|
||||
set_pref(&mut s, "realTimeDrawing", json!(false));
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 100.0, 200.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, 150.0, 200.0), v).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc.guides[0].pos, 150.0, "the guide moves while dragged");
|
||||
s.pointer(&PointerEvent::new(PointerKind::Up, 150.0, 200.0), v).unwrap();
|
||||
assert_eq!((s.doc().unwrap().doc.guides[0].pos, s.doc().unwrap().history.undo.last().map(|e| e.label.as_str())), (150.0, Some("Move Guide")));
|
||||
}
|
||||
|
||||
/// Real-time Drawing turned on mid-drag still applies the deferred preview on commit.
|
||||
#[test]
|
||||
fn real_time_drawing_turned_on_mid_drag_still_commits_deferred_preview() {
|
||||
|
||||
@@ -562,3 +562,25 @@ fn eps_save_bounds_large_page_preview_without_cropping_vector_or_editing_data()
|
||||
assert_eq!(native.artboards, s.doc().unwrap().doc.artboards);
|
||||
assert_eq!(native.layers, s.doc().unwrap().doc.layers);
|
||||
}
|
||||
|
||||
/// #4646: a new document's units and ruler guides survive Save, Close and Open in every format
|
||||
/// that carries the whole document (an SVG keeps them only with Preserve Editing).
|
||||
#[test]
|
||||
fn units_and_ruler_guides_survive_save_and_reopen() {
|
||||
let d = dir("units-guides");
|
||||
for ext in ["vectorcraft", "pdf", "ai", "eps"] {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 200, "height": 100, "units": "Millimeters"})).unwrap();
|
||||
s.execute("guide.add", &json!({"vertical": true, "pos": 50})).unwrap();
|
||||
s.execute("guide.add", &json!({"vertical": false, "pos": 30})).unwrap();
|
||||
rect(&mut s);
|
||||
let p = path(&d, &format!("a.{ext}"));
|
||||
s.execute("document.save", &json!({"path": p})).unwrap();
|
||||
s.execute("file.close", &json!({})).unwrap();
|
||||
s.execute("document.open", &json!({"path": p})).unwrap();
|
||||
let doc = &s.doc().unwrap().doc;
|
||||
let guides: Vec<_> = doc.guides.iter().map(|g| (g.vertical, g.pos)).collect();
|
||||
assert_eq!((doc.units, guides), (vectorcraft_doc::Unit::Millimeters, vec![(true, 50.0), (false, 30.0)]), "{ext}");
|
||||
}
|
||||
let _ = std::fs::remove_dir_all(d);
|
||||
}
|
||||
|
||||
@@ -743,8 +743,9 @@ impl Session {
|
||||
Action::Begin(label) => self.begin_interaction(&label)?,
|
||||
Action::Preview(cmd, p) => {
|
||||
// Performance › Real-time Drawing and Editing (#394): off, remember the latest
|
||||
// params and apply them once on Commit instead of every move.
|
||||
if !self.prefs.real_time_drawing {
|
||||
// params and apply them once on Commit instead of every move. A ruler guide
|
||||
// being dragged still shows: the guide is all there is to see (#4646).
|
||||
if !self.prefs.real_time_drawing && !matches!(cmd.as_str(), "guide.add" | "guide.move") {
|
||||
self.clear_deferred_overlay_cache();
|
||||
let st = self.doc_mut()?;
|
||||
if let Some(it) = &mut st.interaction {
|
||||
|
||||
Reference in New Issue
Block a user