mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-23 02:44:24 +01:00
Merge pull request #8956 from dotCooCoo/fix/curvature-circle-skip-on-selection
Shapes: the Curvature Circle tool reaches its circles again after Deselect
This commit is contained in:
6 files changed
+88
-7
No files matched your search
@@ -176,6 +176,13 @@ fn click(s: &mut Session, mods: Mods, x: f64, y: f64) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The path the last `shape.curvatureCircle` drew on.
|
||||
fn drawn_on(s: &Session) -> NodeId {
|
||||
let (cmd, p) = s.journal.last().unwrap().clone();
|
||||
assert_eq!(cmd, C);
|
||||
id_of(&p)
|
||||
}
|
||||
|
||||
/// With the Curvature Circle tool, a click on a path draws the circle that matches it there, in
|
||||
/// one undo step; with Shift, on the other side. A click on a straight line or away from every
|
||||
/// path draws nothing.
|
||||
@@ -223,4 +230,27 @@ fn the_next_click_passes_over_the_circle_the_tool_drew() {
|
||||
assert_eq!(object_count(&s), count + 1, "the circle drawn first is within reach again");
|
||||
let third = *s.doc().unwrap().selection.objects.first().unwrap();
|
||||
assert!(bounds_are(&s, third, Rect::new(100.0, 200.0, 300.0, 400.0)), "the click drew the first circle's own circle");
|
||||
assert_eq!(drawn_on(&s), first, "the click hit the first circle");
|
||||
}
|
||||
|
||||
/// After Deselect, the pointer reaches the circle the tool drew again, with no edit in between,
|
||||
/// and still does when the circle is selected again before the pointer moves.
|
||||
#[test]
|
||||
fn after_deselect_the_pointer_reaches_the_circle_the_tool_drew() {
|
||||
for reselect in [false, true] {
|
||||
let mut s = session();
|
||||
let path = parabola(&mut s);
|
||||
s.select_tool("curvatureCircle", view()).unwrap();
|
||||
click(&mut s, Mods::default(), 200.0, 200.0);
|
||||
let first = *s.doc().unwrap().selection.objects.first().unwrap();
|
||||
assert_eq!(drawn_on(&s), path);
|
||||
let undo = undo_len(&s);
|
||||
s.execute("select.none", &json!({})).unwrap();
|
||||
if reselect {
|
||||
s.execute("select.set", &json!({"ids": [first.0]})).unwrap();
|
||||
}
|
||||
assert_eq!(undo_len(&s), undo, "Deselect is not an edit");
|
||||
click(&mut s, Mods::default(), 280.0, 236.0);
|
||||
assert_eq!(drawn_on(&s), first, "the click hit the circle drawn first ({reselect})");
|
||||
}
|
||||
}
|
||||
@@ -1548,11 +1548,12 @@ impl Session {
|
||||
}
|
||||
|
||||
/// Let the active tool finish work a command from outside it ended ([`vectorcraft_tools::Tool::after_command`]):
|
||||
/// the Type tool and the Eyedropper clear a character range whose text is no longer selected.
|
||||
/// the Type tool and the Eyedropper clear a character range whose text is no longer selected,
|
||||
/// and the Curvature Circle tool lets the pointer reach its circles once none is selected.
|
||||
/// After `edit.undo` or `edit.redo` (`cmd`), the tool is told first, so the Type tool puts the
|
||||
/// caret where the step changed the text.
|
||||
pub(crate) fn after_command(&mut self, cmd: Option<&str>) {
|
||||
if self.in_tool_actions || (!self.tool.wants_text() && self.tool.id() != "eyedropper") {
|
||||
if self.in_tool_actions || (!self.tool.wants_text() && !matches!(self.tool.id(), "eyedropper" | vectorcraft_tools::curvature_circle::ID)) {
|
||||
return;
|
||||
}
|
||||
if let Some(cmd @ ("edit.undo" | "edit.redo")) = cmd {
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
//! the side the path bends toward; with Shift held at the press, on the other side. On a straight
|
||||
//! stretch, at a cusp, at a corner, or where the circle would reach past the canvas, the pointer
|
||||
//! shows "Straight segment", "Cusp", "Corner" or "Circle too large" instead, and a click draws
|
||||
//! nothing. The pointer passes over the circles the tool drew until another tool is chosen or an
|
||||
//! edit, Undo or Redo is made outside the tool.
|
||||
//! nothing. The pointer passes over the circles the tool drew until the selection holds none of
|
||||
//! them, another tool is chosen, another document becomes active, or an edit, Undo or Redo is
|
||||
//! made outside the tool.
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
@@ -58,10 +59,24 @@ pub struct CurvatureCircleTool {
|
||||
/// The press in progress, where the pointer was pressed: what a release draws.
|
||||
press: Option<(Hit, bool)>,
|
||||
from: Point,
|
||||
/// The circles the tool drew since the history last moved outside it.
|
||||
/// The circles the tool drew since the history last moved outside it or the selection last
|
||||
/// held none of them.
|
||||
drawn: HashSet<NodeId>,
|
||||
}
|
||||
|
||||
impl CurvatureCircleTool {
|
||||
/// After Deselect or a selection made outside the tool, the selection holds none of the
|
||||
/// circles the tool drew, and the pointer reaches them again.
|
||||
/// Returns whether it forgot any.
|
||||
fn forget_unselected(&mut self, cx: &ToolContext) -> bool {
|
||||
if self.drawn.is_empty() || cx.selection.objects.iter().any(|id| self.drawn.contains(id)) {
|
||||
return false;
|
||||
}
|
||||
self.drawn.clear();
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// The nearest point within reach of `p` on the paths a click can pick, guides and the paths in
|
||||
/// `skip` left out; of paths at the same distance, a selected one, then the one on top.
|
||||
fn hit_at(cx: &ToolContext, p: Point, skip: &HashSet<NodeId>) -> Option<Hit> {
|
||||
@@ -118,6 +133,7 @@ impl Tool for CurvatureCircleTool {
|
||||
if !ev.pos.is_finite() {
|
||||
return vec![];
|
||||
}
|
||||
self.forget_unselected(cx);
|
||||
match ev.kind {
|
||||
PointerKind::Move => {
|
||||
self.hover = hit_at(cx, ev.pos, &self.drawn).map(|h| (h, ev.mods.shift));
|
||||
@@ -185,6 +201,16 @@ impl Tool for CurvatureCircleTool {
|
||||
}
|
||||
}
|
||||
|
||||
/// A command from outside the tool (Deselect, a pick in the Layers panel) may leave none of the
|
||||
/// circles the tool drew selected. The circle shown under the pointer then waits for the next
|
||||
/// hover.
|
||||
fn after_command(&mut self, cx: &ToolContext) -> Vec<Action> {
|
||||
if self.forget_unselected(cx) {
|
||||
self.hover = None;
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn deactivate(&mut self, _cx: &ToolContext) -> Vec<Action> {
|
||||
self.hover = None;
|
||||
self.press = None;
|
||||
|
||||
@@ -198,6 +198,27 @@ fn the_next_click_passes_over_the_circle_just_drawn() {
|
||||
assert_eq!(params(&click(&mut t, &cx, (302.0, 200.0), Mods::default()))["id"], json!(drawn.0));
|
||||
}
|
||||
|
||||
/// Once the selection holds none of the circles the tool drew (after Deselect, or a pick of another
|
||||
/// object), the pointer reaches them again.
|
||||
#[test]
|
||||
fn a_selection_without_the_drawn_circles_makes_them_reachable() {
|
||||
let line = PathData::from_bezpath(&vectorcraft_geom::BezPath::from_svg("M0 450 L400 450").unwrap());
|
||||
let d = doc_with(&[circle(), circle(), line]);
|
||||
let ids: Vec<NodeId> = d.layers[0].children().unwrap().iter().rev().map(|n| n.id).collect();
|
||||
let (drawn, under, other) = (ids[0], ids[1], ids[2]);
|
||||
let p = paint();
|
||||
let holding = Selection { objects: vec![drawn], ..Selection::default() };
|
||||
let both = Selection { objects: vec![drawn, other], ..Selection::default() };
|
||||
let none = Selection::default();
|
||||
let picked = Selection { objects: vec![other], ..Selection::default() };
|
||||
for (after, want) in [(&holding, under), (&both, under), (&none, drawn), (&picked, drawn)] {
|
||||
let mut t = CurvatureCircleTool::default();
|
||||
t.notify(&ToolContext { smart_guides: false, ..cx(&d, &holding, &p) }, "created");
|
||||
let cx = ToolContext { smart_guides: false, ..cx(&d, after, &p) };
|
||||
assert_eq!(params(&click(&mut t, &cx, (302.0, 200.0), Mods::default()))["id"], json!(want.0), "{:?}", after.objects);
|
||||
}
|
||||
}
|
||||
|
||||
/// A press that a second finger or a canceled touch drops draws nothing on the release, and an
|
||||
/// edit made outside the tool drops what the pointer was over.
|
||||
#[test]
|
||||
|
||||
@@ -375,6 +375,7 @@ pub(crate) fn candidate_paths(cx: &ToolContext) -> Vec<NodeId> {
|
||||
}
|
||||
});
|
||||
rest.reverse();
|
||||
// The loop skips ids that are already listed.
|
||||
let mut seen: std::collections::HashSet<NodeId> = v.iter().copied().collect();
|
||||
for id in rest {
|
||||
if seen.insert(id) {
|
||||
|
||||
+4
-2
@@ -7291,8 +7291,10 @@ it touches and, with Measurement Labels on, its radius by the pointer, followed
|
||||
radius. A click draws the circle, and a press dragged 2 screen points or more, or canceled with Escape, draws nothing;
|
||||
Shift held at the press puts the circle on the other side of the path. On a straight segment, at a cusp, at a corner
|
||||
anchor, or where the circle would reach past the canvas, the pointer shows "Straight segment", "Cusp", "Corner" or
|
||||
"Circle too large", and a click draws nothing. The pointer passes over the circles the tool drew until another tool
|
||||
is chosen or an edit, Undo or Redo is made outside the tool.
|
||||
"Circle too large", and a click draws nothing. The pointer passes over the circles the tool drew until Deselect or a
|
||||
selection made outside the tool leaves none of them selected, another tool is chosen, another document becomes
|
||||
active, or an edit, Undo or Redo is made outside the tool. Selecting one of them again does not put it back out of
|
||||
reach.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"shape.curvatureCircle","params":{"id":12,"segment":0,"t":0.5}}}
|
||||
|
||||
Reference in new issue
Block a user