mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-17 20:52:08 +00:00
#4943: keep the language-list note in the UI parity status line
The new conflict was only that status line. Upstream's longer change list is kept, with the #4943 language-list clause in front. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1027,6 +1027,12 @@ fn cut(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if !direct { clear(s, &json!({ "ids": roots, "guides": true })) } else { cut_direct_selection(s, &roots) }
|
||||
}
|
||||
|
||||
/// Remove the geometry copied by a direct-selection Cut, including selected guides in one edit.
|
||||
/// Select every surviving piece while retaining intentional compound-path structure.
|
||||
/// `roots` contains the copied targets: whole-object roots are removed in full, while partial paths
|
||||
/// lose only the copied geometry. An exhausted partial path is removed, along with its compound
|
||||
/// parent if now empty; layers remain. Returns JSON `null` on success, replacing direct-selection
|
||||
/// references with surviving object IDs.
|
||||
fn cut_direct_selection(s: &mut Session, roots: &[NodeId]) -> Result<Value> {
|
||||
let st = s.doc()?;
|
||||
let sel = st.selection.clone();
|
||||
@@ -1035,6 +1041,7 @@ fn cut_direct_selection(s: &mut Session, roots: &[NodeId]) -> Result<Value> {
|
||||
let gone = selection.guides.clone();
|
||||
d.retain_guides(selection, |i, _| !gone.contains(&i));
|
||||
let mut survivors = vec![];
|
||||
let mut pieces = super::pathops::Beside::replacing(d, roots);
|
||||
for id in roots {
|
||||
let Some(node) = d.node(*id) else { continue };
|
||||
let has_direct = sel.anchors.contains_key(id) || sel.segments.contains_key(id);
|
||||
@@ -1042,20 +1049,22 @@ fn cut_direct_selection(s: &mut Session, roots: &[NodeId]) -> Result<Value> {
|
||||
d.remove(*id)?;
|
||||
continue;
|
||||
}
|
||||
let Some(path) = node.path_data() else {
|
||||
if node.path_data().is_none() {
|
||||
d.remove(*id)?;
|
||||
continue;
|
||||
};
|
||||
}
|
||||
let original = super::path::deletion_source(d, *id)?;
|
||||
|
||||
let seg_refs = sel.segments.get(id);
|
||||
let anchor_refs = sel.anchors.get(id);
|
||||
let mut subpaths = Vec::new();
|
||||
for (si, sp) in path.subpaths.iter().enumerate() {
|
||||
let cuts = super::clipboard::subpath_selected_segments(sp, si, seg_refs, anchor_refs);
|
||||
let owned = std::mem::take(&mut super::path::path_mut(d, *id)?.subpaths);
|
||||
for (si, sp) in owned.into_iter().enumerate() {
|
||||
let cuts = super::clipboard::subpath_selected_segments(&sp, si, seg_refs, anchor_refs);
|
||||
if cuts.is_empty() {
|
||||
subpaths.push(sp.clone());
|
||||
subpaths.push(sp);
|
||||
} else {
|
||||
subpaths.extend(super::path::without_segments(sp.clone(), &cuts));
|
||||
subpaths.extend(super::path::without_segments(sp, &cuts));
|
||||
}
|
||||
}
|
||||
subpaths.retain(|sp| sp.anchors.len() >= 2);
|
||||
@@ -1068,11 +1077,10 @@ fn cut_direct_selection(s: &mut Session, roots: &[NodeId]) -> Result<Value> {
|
||||
d.remove(p)?;
|
||||
}
|
||||
} else {
|
||||
let path_node = super::path::path_mut(d, *id)?;
|
||||
path_node.subpaths = subpaths;
|
||||
survivors.push(*id);
|
||||
survivors.extend(super::path::replace_deleted_pieces(d, &mut pieces, original, subpaths)?);
|
||||
}
|
||||
}
|
||||
pieces.finish(d)?;
|
||||
selection.set(survivors);
|
||||
selection.anchors.clear();
|
||||
selection.segments.clear();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Path editing commands (used by the Pen and Direct Selection tools and Object → Path).
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_doc::{Document, Node, NodeId, NodeKind, Scaling};
|
||||
@@ -1206,6 +1207,11 @@ fn convert_anchors(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
ok()
|
||||
}
|
||||
|
||||
/// Delete direct-selected anchors or segments and whole selected objects in one edit.
|
||||
/// Leave surviving pieces selected, splitting ordinary contours into independent sibling objects.
|
||||
/// `p.guides: true` also removes the selected ruler guides in that edit; otherwise guides remain.
|
||||
/// Layers are retained, and an object removed with a selected ancestor is not removed twice.
|
||||
/// Returns JSON `null` on success; selection is replaced by the surviving object IDs.
|
||||
pub(crate) fn delete_anchors(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// `guides: true` (Cut, #3226): the selected ruler guides go in the same undo step.
|
||||
let with_guides = switch_or(p, "guides", false, "path.deleteAnchors")?;
|
||||
@@ -1237,11 +1243,13 @@ pub(crate) fn delete_anchors(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if d.node(*id).is_none() {
|
||||
continue;
|
||||
}
|
||||
let remove_node = {
|
||||
let original = deletion_source(d, *id)?;
|
||||
let subpaths: Vec<SubPath> = {
|
||||
let path = path_mut(d, *id)?;
|
||||
let subpaths = std::mem::take(&mut path.subpaths);
|
||||
if let Some(refs) = segments.get(id) {
|
||||
// A segment pick cuts its connection, keeping every neighboring cubic.
|
||||
path.subpaths = std::mem::take(&mut path.subpaths)
|
||||
subpaths
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.flat_map(|(si, sp)| {
|
||||
@@ -1249,11 +1257,11 @@ pub(crate) fn delete_anchors(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
without_segments(sp, &cuts)
|
||||
})
|
||||
.filter(|s| s.anchors.len() >= 2)
|
||||
.collect();
|
||||
.collect()
|
||||
} else {
|
||||
// Remove every selected anchor against the original indexes, keeping surviving
|
||||
// stretches separate rather than joining across deleted anchors.
|
||||
path.subpaths = std::mem::take(&mut path.subpaths)
|
||||
subpaths
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.flat_map(|(si, sp)| {
|
||||
@@ -1261,16 +1269,14 @@ pub(crate) fn delete_anchors(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
without_anchors(sp, &gone)
|
||||
})
|
||||
.filter(|s| s.anchors.len() >= 2)
|
||||
.collect();
|
||||
.collect()
|
||||
}
|
||||
path.subpaths.retain(|s| s.anchors.len() >= 2);
|
||||
path.subpaths.is_empty()
|
||||
};
|
||||
if remove_node {
|
||||
if subpaths.is_empty() {
|
||||
emptied.put(d, *id, vec![])?;
|
||||
} else {
|
||||
// The remainder is selected whole, so the next Delete removes it.
|
||||
survivors.push(*id);
|
||||
// Every remaining piece is selected whole, so the next Delete removes them.
|
||||
survivors.extend(replace_deleted_pieces(d, &mut emptied, original, subpaths)?);
|
||||
}
|
||||
}
|
||||
emptied.finish(d)?;
|
||||
@@ -1280,6 +1286,47 @@ pub(crate) fn delete_anchors(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
ok()
|
||||
}
|
||||
|
||||
/// Retain path `id` from `d` without copying its geometry before deletion takes its subpaths.
|
||||
/// The shared snapshot supplies the original path classification and, only if needed, gradient
|
||||
/// bounds after the working node's geometry has moved. Returns `NoNode` for a missing/non-path ID.
|
||||
pub(super) fn deletion_source(d: &Document, id: NodeId) -> Result<Arc<Node>> {
|
||||
let (parent, index, _) = d.position(id).ok_or(EngineError::NoNode(id))?;
|
||||
// Verify the cached position still names this path before retaining the shared node.
|
||||
d.children(parent)
|
||||
.and_then(|children| children.get(index))
|
||||
.filter(|n| n.id == id && n.path_data().is_some())
|
||||
.cloned()
|
||||
.ok_or(EngineError::NoNode(id))
|
||||
}
|
||||
|
||||
/// Replace the deleted path in `d` with the nonempty surviving runs in `subpaths`.
|
||||
/// `original` must be retained by [`deletion_source`] before taking the working node's geometry.
|
||||
/// An ordinary single-contour source becomes siblings; multi-subpath paths and compound members
|
||||
/// retain their node. Only actual splits pin unplaced gradients to `original`'s bounds; already
|
||||
/// placed gradients and connected remainders retain their placement behavior.
|
||||
///
|
||||
/// Returns the surviving IDs in `subpaths` order (the first keeps the source ID). The original
|
||||
/// node's geometry is updated immediately. Replacements are handed to `beside`, which may defer
|
||||
/// insertion; the caller must finish that [`Beside`] before using new IDs in `d`.
|
||||
/// Missing/invalid paths return an error.
|
||||
pub(super) fn replace_deleted_pieces(d: &mut Document, beside: &mut Beside, original: Arc<Node>, subpaths: Vec<SubPath>) -> Result<Vec<NodeId>> {
|
||||
let id = original.id;
|
||||
let single = original.path_data().is_some_and(|p| p.subpaths.len() == 1);
|
||||
if single && compound_or_self(d, id) == id {
|
||||
// Pin only actual splits: each new object's smaller bounds would otherwise refit its gradients.
|
||||
if subpaths.len() > 1
|
||||
&& original.appearance.has_unplaced_gradient()
|
||||
&& let Some(bounds) = original.geometric_bounds()
|
||||
{
|
||||
d.node_mut(id).ok_or(EngineError::NoNode(id))?.appearance.pin_gradients(bounds);
|
||||
}
|
||||
super::draw2::replace_with_pieces(d, beside, id, subpaths.into_iter().map(PathData::single).collect())
|
||||
} else {
|
||||
path_mut(d, id)?.subpaths = subpaths;
|
||||
Ok(vec![id])
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove anchors and their incident segments, keeping each surviving stretch as an open path.
|
||||
/// Only a closed path can have a surviving stretch that wraps past the last anchor.
|
||||
fn without_anchors(sp: SubPath, removed: &BTreeSet<usize>) -> Vec<SubPath> {
|
||||
|
||||
@@ -2698,11 +2698,26 @@ fn pen_cmd_selected_anchors_are_what_copy_and_cut_take() {
|
||||
assert_eq!(s.doc().unwrap().selection.anchors[&id], [(0, 1), (0, 2)].into());
|
||||
s.execute("edit.copy", &json!({})).unwrap();
|
||||
assert_eq!(pasted(&mut s), [2]);
|
||||
// Cut takes the segment between them out of the path, as with Direct Selection chosen.
|
||||
// Cut takes the segment between them. The two surviving runs of an ordinary path
|
||||
// become independent objects, and this path keeps the first run (#3380).
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
let original = path(&s, id);
|
||||
let picked = s.doc().unwrap().selection.clone();
|
||||
s.execute("edit.cut", &json!({})).unwrap();
|
||||
let left = path(&s, id).subpaths.iter().map(|sp| sp.anchors.len()).collect::<Vec<_>>();
|
||||
assert_eq!((s.clipboard.nodes.len(), left), (1, vec![2, 2]));
|
||||
let left = paths(&s);
|
||||
assert_eq!(left.len(), 2);
|
||||
assert_eq!(left[0].0, id);
|
||||
assert!(left.iter().all(|(_, p)| p.subpaths.len() == 1 && !p.subpaths[0].closed));
|
||||
assert_eq!(left[0].1.subpaths[0].anchors, original.subpaths[0].anchors[..2]);
|
||||
assert_eq!(left[1].1.subpaths[0].anchors, original.subpaths[0].anchors[2..]);
|
||||
assert_eq!(s.doc().unwrap().selection.objects, left.iter().map(|(id, _)| *id).collect::<Vec<_>>());
|
||||
assert_eq!(s.clipboard.nodes.len(), 1);
|
||||
assert_eq!(s.clipboard.nodes[0].path_data().unwrap().subpaths[0].anchors, original.subpaths[0].anchors[1..3]);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(paths(&s), vec![(id, original.clone())]);
|
||||
assert_eq!(s.doc().unwrap().selection, picked);
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
assert_eq!(paths(&s), left);
|
||||
// Drawing on: the last anchor the Pen leaves selected doesn't make Copy take that anchor.
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
@@ -3412,6 +3427,7 @@ fn a_filled_pencil_path_keeps_no_stroke() {
|
||||
assert!(!s.doc().unwrap().doc.node(id).unwrap().appearance.stroke_paint().is_none());
|
||||
}
|
||||
|
||||
/// Interior and endpoint deletions preserve each surviving run without adding connecting segments.
|
||||
#[test]
|
||||
fn open_anchor_delete_splits_runs_without_new_connections() {
|
||||
let cases = [
|
||||
@@ -3439,16 +3455,19 @@ fn open_anchor_delete_splits_runs_without_new_connections() {
|
||||
assert!(s.doc().unwrap().doc.node(id).is_none(), "only isolated points remain: {removed:?}");
|
||||
assert!(s.doc().unwrap().selection.objects.is_empty());
|
||||
} else {
|
||||
let result = path(&s, id);
|
||||
assert_eq!(result.subpaths.len(), expected.len(), "deleted anchors: {removed:?}");
|
||||
for (sp, indices) in result.subpaths.iter().zip(&expected) {
|
||||
let pieces = &s.doc().unwrap().selection.objects;
|
||||
assert_eq!(pieces.len(), expected.len(), "deleted anchors: {removed:?}");
|
||||
assert_eq!(pieces[0], id);
|
||||
for (piece, indices) in pieces.iter().zip(&expected) {
|
||||
let result = path(&s, *piece);
|
||||
assert_eq!(result.subpaths.len(), 1);
|
||||
let sp = &result.subpaths[0];
|
||||
assert!(!sp.closed);
|
||||
assert_eq!(sp.anchors.iter().map(|a| a.p).collect::<Vec<_>>(), indices.iter().map(|&i| original.anchors[i].p).collect::<Vec<_>>());
|
||||
for (segment, pair) in indices.windows(2).enumerate() {
|
||||
assert_eq!(sp.segment(segment), original.segment(pair[0]));
|
||||
}
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![id]);
|
||||
}
|
||||
assert_eq!(undo_steps(&s), undo + 1);
|
||||
assert!(s.doc().unwrap().selection.anchors.is_empty() && s.doc().unwrap().selection.segments.is_empty());
|
||||
@@ -3547,6 +3566,7 @@ fn open_anchor_delete_does_not_change_explicit_remove_anchors() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Baked transforms and mixed whole/partial selection survive splitting and atomic Undo/Redo.
|
||||
#[test]
|
||||
fn open_anchor_delete_after_transform_keeps_mixed_selection_atomic() {
|
||||
use vectorcraft_geom::Affine;
|
||||
@@ -3584,13 +3604,17 @@ fn open_anchor_delete_after_transform_keeps_mixed_selection_atomic() {
|
||||
let st = s.doc().unwrap();
|
||||
assert!(st.doc.node(whole).is_none());
|
||||
assert_eq!(st.doc.node(untouched), before.node(untouched));
|
||||
let result = path(&s, id);
|
||||
assert_eq!(result.subpaths.len(), 2);
|
||||
for (sp, segment) in result.subpaths.iter().zip([0, 3]) {
|
||||
let pieces = st.selection.objects.clone();
|
||||
assert_eq!(pieces.len(), 2);
|
||||
assert_eq!(pieces[0], id);
|
||||
for (piece, segment) in pieces.iter().zip([0, 3]) {
|
||||
let result = path(&s, *piece);
|
||||
assert_eq!(result.subpaths.len(), 1);
|
||||
let sp = &result.subpaths[0];
|
||||
assert_eq!(sp.segment_count(), 1);
|
||||
assert_eq!(sp.segment(0), original.subpaths[0].segment(segment));
|
||||
}
|
||||
assert_eq!(st.selection.objects, vec![id]);
|
||||
assert_eq!(st.selection.objects, pieces);
|
||||
assert!(st.selection.anchors.is_empty() && st.selection.segments.is_empty());
|
||||
assert_eq!(undo_steps(&s), undo + 1);
|
||||
let after = st.doc.clone();
|
||||
@@ -3599,7 +3623,7 @@ fn open_anchor_delete_after_transform_keeps_mixed_selection_atomic() {
|
||||
assert_eq!(s.doc().unwrap().selection, selection);
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().doc, after);
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![id]);
|
||||
assert_eq!(s.doc().unwrap().selection.objects, pieces);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user