Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge PR #5412: fix(pen): an unclosed path stays with its document (#5373)

aionggf094216481ab
diff --cc crates/ui-egui/src/lib.rs
index 6f54ed161,fd922edeb..948fffa09
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@@ -1415,7 -1190,8 +1414,9 @@@ impl PhotocraftApp
// ... and to the document it was started on.
crate::canvas::polygon_cancel_stale(self);
crate::crop_ui::cancel_stale(self);
+ crate::perspective_crop_ui::cancel_stale(self);
+ // A pen path under construction belongs to the document it was started on too.
+ vector_ui::cancel_stale(self);
let ids: Vec<DocId> = self.session.documents().iter().map(|d| d.doc.id).collect();
// Where the document of view `i` is now. Views not tracked yet keep their index.
let now = |i: usize| match self.view_docs.get(i) {
diff --cc crates/ui-egui/src/vector_ui.rs
index 3cba132f2,f6b65260a..fdc712318
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@@ -237,14 -222,13 +237,20 @@@ pub fn closes_path_at(app: &PhotocraftA
/// or add a new anchor (dragging a new anchor pulls symmetrical handles). With ⇧ a new anchor
/// lands on the nearest 45° ray from the previous one, at the pointer's projection onto it.
pub fn pen_down(app: &mut PhotocraftApp, x: f64, y: f64, shift: bool) {
+ if !cancel_stale(app) {
+ return;
+ }
let tol = 6.0 / app.point_zoom().max(0.01) as f64;
+ if app.ui.pen.is_none() {
+ app.ui.pen_doc = app.session.active().map(|st| st.doc.id);
+ }
+ // A press on an endpoint of an open path carries on drawing it, as in Photoshop (#6593): the
+ // press then acts on its last anchor, so a drag pulls out the next segment's handle.
+ if app.ui.pen.as_ref().is_none_or(|p| p.knots.is_empty())
+ && let Some(resumed) = resume_at(app, x, y, tol)
+ {
+ app.ui.pen = Some(resumed);
+ }
let pen = app.ui.pen.get_or_insert_with(PenPath::default);
if let Some(first) = pen.knots.first().map(|k| k[0])
&& on_closing_anchor(pen, x, y, tol)
@@@ -307,17 -291,10 +313,20 @@@ fn shift_45(origin: [f64; 2], p: [f64;
/// clicking the first anchor commits the path. Therefore Cmd/Ctrl+Z must consume one
/// knot rather than undoing an unrelated, already committed document operation.
pub fn pen_undo_last_point(app: &mut PhotocraftApp) -> bool {
+ if !cancel_stale(app) {
+ return false;
+ }
let Some(pen) = app.ui.pen.as_mut() else { return false };
+ // A resumed path's own anchors are not the draft's to take back: undoing past the ones added
+ // since it resumed drops the draft and leaves the path as it was (#6593).
+ if pen.resumes.as_ref().is_some_and(|r| pen.knots.len() <= r.was.knots.len()) {
+ // A ⌘/Ctrl selection on the draft goes with it.
+ if app.ui.direct_selection.target == Some(crate::direct_select::PathRef::Pen) {
+ app.ui.direct_selection = Default::default();
+ }
+ app.ui.pen = None;
+ return true;
+ }
if pen.knots.pop().is_none() {
return false;
}