mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-31 05:07:51 -06:00
Isolation mode: double-clicking a single object isolates it
With Double Click To Isolate on, the Selection tool isolated groups only. A double-click on a single path, compound path, image, mesh or placed file now isolates it too, as the public documentation describes. Type still switches to the Type tool; blends, envelopes, repeats and symbol instances keep their own editing modes. While a single object is isolated only it is hit, marqueed and taken by Select All, new art goes beside it in its group or layer, and a double-click on the empty canvas leaves with it selected. object.isolate accepts any object except type.
This commit is contained in:
@@ -298,6 +298,60 @@ fn selection_preferences_drive_the_selection_tool() {
|
||||
assert!(double(&mut s).is_some(), "on: the group is isolated");
|
||||
}
|
||||
|
||||
/// Double Click To Isolate: a double-click with the Selection tool isolates a single object too,
|
||||
/// not only a group. Inside, only it is hit, marqueed and selected by Select All; new art goes
|
||||
/// beside it; a double-click on the empty canvas leaves, with it selected. Type isn't isolated:
|
||||
/// a double-click on it switches to the Type tool.
|
||||
#[test]
|
||||
fn double_clicking_a_single_object_isolates_it() {
|
||||
use vectorcraft_tools::{PointerEvent, PointerKind};
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = |v: Value| NodeId(v["id"].as_u64().unwrap());
|
||||
let rect = |s: &mut Session, x: f64| id(s.execute("shape.rectangle", &json!({"x": x, "y": 100, "width": 50, "height": 50})).unwrap());
|
||||
let (a, b) = (rect(&mut s, 100.0), rect(&mut s, 200.0));
|
||||
s.select_tool("selection", ViewInfo::default()).unwrap();
|
||||
let ev = |s: &mut Session, kinds: &[PointerKind], x: f64, y: f64| {
|
||||
for k in kinds {
|
||||
s.pointer(&PointerEvent::new(*k, x, y), ViewInfo::default()).unwrap();
|
||||
}
|
||||
};
|
||||
let click = [PointerKind::Down, PointerKind::Up];
|
||||
let double = [PointerKind::DoubleClick];
|
||||
ev(&mut s, &double, 125.0, 125.0);
|
||||
assert_eq!(s.doc().unwrap().isolation, Some(a));
|
||||
// Only the isolated object is hit: a click on the other selects nothing.
|
||||
ev(&mut s, &click, 225.0, 125.0);
|
||||
assert!(s.doc().unwrap().selection.objects.is_empty());
|
||||
ev(&mut s, &click, 125.0, 125.0);
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![a]);
|
||||
// A marquee over both and Select All take it alone.
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
ev(&mut s, &[PointerKind::Down], 90.0, 90.0);
|
||||
ev(&mut s, &[PointerKind::Move, PointerKind::Up], 300.0, 300.0);
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![a]);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
s.execute("select.all", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![a]);
|
||||
// A second double-click on it stays in isolation; new art lands on its layer.
|
||||
ev(&mut s, &double, 125.0, 125.0);
|
||||
assert_eq!(s.doc().unwrap().isolation, Some(a));
|
||||
let c = rect(&mut s, 300.0);
|
||||
let st = s.doc().unwrap();
|
||||
assert_eq!(st.doc.parent_of(c), st.doc.parent_of(a));
|
||||
// A double-click on the empty canvas leaves isolation, the object selected.
|
||||
ev(&mut s, &double, 50.0, 350.0);
|
||||
let st = s.doc().unwrap();
|
||||
assert_eq!((st.isolation, st.selection.objects.clone()), (None, vec![a]));
|
||||
assert!(st.doc.node(b).is_some());
|
||||
// Type is not isolated.
|
||||
let t = id(s.execute("text.create", &json!({"x": 100, "y": 300, "text": "Type"})).unwrap());
|
||||
assert!(s.execute("object.isolate", &json!({"id": t.0})).is_err());
|
||||
s.execute("prefs.set", &json!({"key": "doubleClickToIsolate", "value": false})).unwrap();
|
||||
ev(&mut s, &double, 225.0, 125.0);
|
||||
assert_eq!(s.doc().unwrap().isolation, None, "off: no isolation");
|
||||
}
|
||||
|
||||
/// General › Use Precise Cursors (#394): the Pen's pointer becomes a crosshair; the Selection
|
||||
/// tool's arrow stays.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user