Merge pull request #9973 from dotCooCoo/fix/layers-drop-filter-tests

Layers: the trash footer takes an appearance dragged from a target circle
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 13:36:43 -08:00
commit 747dd28162
3 files changed
+284 -4

No files matched your search

+3 -3
View File
@@ -452,12 +452,12 @@ pub(crate) fn footer(tree: &DocLayers, ui: &mut Ui, out: &mut Vec<(String, Value
let (nodes, guides) = row_ids(&drag.layers());
own(drag) && !nodes.is_empty() && guides.is_empty() && !root.is_some_and(|r| nodes.contains(&r.0))
};
let (uid, reverts) = (st.uid, st.reverts);
let actions = [
// PLAN: the framework's `accepts_drops` takes one payload type, so Delete cannot also take
// `PanelDrag` (the appearance drop `footer_drop` maps); it needs a second payload there.
FooterAction::new(icon("trash-2"), tl!("Delete Selection").to_string())
.takes_drops_disabled(true)
.accepts_drops(move |d: &LayersDrag<RowId>| own(d) && !d.layers().is_empty()),
.accepts_drops(move |d: &LayersDrag<RowId>| own(d) && !d.layers().is_empty())
.also_accepts_drops(move |d: &PanelDrag| d.appearance_for(uid, reverts).is_some()),
FooterAction::new(icon("file-plus"), tl!("Create New Layer").to_string()).enabled(new_layer_ok).accepts_drops(duplicate),
FooterAction::new(icon("plus"), tl!("Create New Sublayer").to_string()).enabled(new_sublayer_ok),
FooterAction::new(icon("frame"), tl!("Make/Release Clipping Mask").to_string()),
+280
View File
@@ -558,6 +558,99 @@ fn layer_row_footer_drops_after_next_document_leave_the_new_document_alone() {
}
}
/// Whether object `id` in the active document has a basic appearance.
fn basic(app: &VectorcraftApp, id: NodeId) -> bool {
app.session.active().unwrap().doc.node(id).unwrap().appearance.is_basic()
}
/// A target circle dropped on Delete Selection reduces its row's appearance to a basic appearance and keeps the row;
/// Create New Layer refuses it. Neither button takes a paint or the selected art dragged from a panel.
#[test]
fn delete_selection_reduces_a_dropped_appearance_to_basic() {
use crate::panel_drag::PanelDrag;
use crate::tests::panel_harness::Panel;
use craft::ui::contract::Role;
use craft::ui::runtime::drag;
let (mut app, _, [a, b]) = two_rects();
name_row(&mut app, a, "A");
name_row(&mut app, b, "B");
app.run("appearance.addFill", json!({"ids": [a.0]})).unwrap();
app.run("select.none", json!({})).unwrap();
assert!(!basic(&app, a) && basic(&app, b));
let rows = rows_of(&app);
let mut panel = Panel::new(app, drag_sources_and_layers);
for (name, role) in [("Dragged paint", Role::LIST_ITEM), ("Dragged art", Role::LIST_ITEM), ("Target A", Role::BUTTON)] {
for button in ["Delete Selection", "Create New Layer"] {
if name == "Target A" && button == "Delete Selection" {
continue;
}
let from = panel.rect_role(name, role).center();
let to = panel.rect(button).center();
panel.drag_hold_role(name, role, to - from);
assert!(drag::active::<PanelDrag>(panel.ctx()).is_some(), "{name} carries its payload");
assert!(drag::mark(panel.ctx()).is_none(), "{button} refuses {name}");
let history = undo_len(&panel.app());
panel.release();
let app = panel.app();
assert_eq!(undo_len(&app), history, "{name} on {button} makes no edit");
assert!(!basic(&app, a) && rows_of(&app) == rows, "{name} on {button} leaves the rows as they were");
}
}
let from = panel.rect_role("Target A", Role::BUTTON).center();
let to = panel.rect("Delete Selection").center();
panel.drag_hold_role("Target A", Role::BUTTON, to - from);
assert!(drag::mark(panel.ctx()).is_some(), "Delete Selection takes a target circle's appearance");
let history = undo_len(&panel.app());
panel.release();
let app = panel.app();
assert!(basic(&app, a) && basic(&app, b), "the dropped appearance is reduced to a basic appearance");
assert_eq!(undo_len(&app), history + 1);
assert_eq!(rows_of(&app), rows, "the row is not deleted");
assert!(crate::dialogs::confirm::open_question(&app).is_none());
}
/// Delete Selection refuses an appearance carried over from another document: held across Next Document and
/// released on the trash, it leaves the object with the same ID there as it was.
#[test]
fn delete_selection_refuses_an_appearance_from_another_document() {
use crate::panel_drag::PanelDrag;
use crate::tests::panel_harness::Panel;
use craft::ui::contract::Role;
use craft::ui::runtime::drag;
use egui::{Key, Modifiers};
let (app, [a, _]) = two_documents_with_a_styled();
let first = app.session.active().unwrap().uid;
let mut panel = Panel::new(app, show);
let from = panel.rect_role("Target A", Role::BUTTON).center();
let to = panel.rect("Delete Selection").center();
panel.drag_hold_role("Target A", Role::BUTTON, to - from);
assert!(drag::mark(panel.ctx()).is_some(), "Delete Selection takes an appearance from its own document");
panel.key(Key::F6, Modifiers::COMMAND);
let history = {
let app = panel.app();
let st = app.session.active().unwrap();
assert_ne!(st.uid, first, "Next Document switches documents during the drag");
st.history.undo.len()
};
let carried = drag::active::<PanelDrag>(panel.ctx());
assert!(matches!(carried.as_deref(), Some(PanelDrag::Appearance { document, source, .. }) if *document == first && *source == a));
assert!(drag::mark(panel.ctx()).is_none(), "Delete Selection refuses an appearance from another document");
panel.release();
{
let app = panel.app();
assert!(!basic(&app, a), "the object with the same ID keeps its appearance");
assert_eq!(undo_len(&app), history, "the foreign drop makes no edit");
}
panel.drag("Target A", "Delete Selection", Modifiers::NONE);
assert!(basic(&panel.app(), a), "a drag within the new document still reduces the appearance");
}
/// The footer's layer count is in the accessibility tree, and it follows the document's layers.
#[test]
fn the_footer_counts_the_layers() {
@@ -987,6 +1080,193 @@ fn row_menus_list_plugin_commands() {
assert!(plugins(&app, b).is_empty(), "removed: no Plug-ins submenu");
}
/// Whether `a` and `b` are within float rounding of each other.
fn near(a: f32, b: f32) -> bool {
(a - b).abs() < 1e-6
}
/// Object `id`'s opacity in the active document.
fn opacity(app: &VectorcraftApp, id: NodeId) -> f32 {
app.session.active().unwrap().doc.node(id).unwrap().opacity
}
/// Two documents, each with rows "A" and "B" of the same local IDs in both; A has a second fill and 30% opacity.
/// The first document is active.
fn two_documents_with_a_styled() -> (VectorcraftApp, [NodeId; 2]) {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
let mut ids = Vec::new();
for _ in 0..2 {
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
let mut add = |x| NodeId(app.run("shape.rectangle", json!({"x": x, "y": 0, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap());
let (a, b) = (add(0), add(60));
name_row(&mut app, a, "A");
name_row(&mut app, b, "B");
app.run("appearance.addFill", json!({"ids": [a.0]})).unwrap();
app.run("transparency.set", json!({"ids": [a.0], "opacity": 30})).unwrap();
app.run("select.none", json!({})).unwrap();
ids.push([a, b]);
}
assert_eq!(ids[0], ids[1], "the documents have different objects with the same local IDs");
assert!(app.session.set_active(0));
(app, ids[0])
}
/// The Layers panel under three list rows that drag, from the active document, a paint, the bottom object as
/// selected art and the bottom object's appearance.
fn drag_sources_and_layers(app: &mut VectorcraftApp, ui: &mut Ui) {
use crate::panel_drag::PanelDrag;
use craft::ui::contract::ListDrag;
use craft::ui::contract::ShowCollection as _;
use craft::ui::list::{List, ListRow};
let st = app.session.active().unwrap();
let (document, reverts) = (st.uid, st.reverts);
let source = st.doc.layers[0].children().unwrap()[0].id;
let drags = [
("Dragged paint", PanelDrag::paint(vectorcraft_color::Paint::None)),
("Dragged art", PanelDrag::Art { document, reverts, ids: vec![source] }),
("Dragged appearance", PanelDrag::Appearance { document, reverts, source }),
];
egui::Panel::top("drag-sources").exact_size(150.0).show(ui, |ui| {
for (name, drag) in drags {
ui.allocate_ui(egui::vec2(ui.available_width(), 48.0), |ui| {
let keys = craft::behavior::keyed(&[0_usize], |key: &usize| *key);
List::<usize>::new(name)
.drag_payload(move |_: &ListDrag<usize>| Some(drag.clone()))
.show_items(ui, &keys, &mut |_, _| ListRow::new(name));
});
}
});
show(app, ui);
}
/// A target circle takes an appearance from another row's circle of the same document: a plain drop moves it and an
/// Alt drop copies it. Held back over its own row's circle, the appearance is refused and nothing changes.
#[test]
fn a_target_circle_takes_another_rows_appearance_and_refuses_its_own() {
use crate::tests::panel_harness::Panel;
use craft::ui::contract::Role;
use craft::ui::runtime::drag;
use egui::{Event, Modifiers};
let (mut app, _, [a, b]) = two_rects();
name_row(&mut app, a, "A");
name_row(&mut app, b, "B");
app.run("transparency.set", json!({"ids": [a.0], "opacity": 30})).unwrap();
app.run("select.none", json!({})).unwrap();
let mut panel = Panel::new(app, show);
let own = panel.rect_role("Target A", Role::BUTTON).center();
let other = panel.rect_role("Target B", Role::BUTTON).center();
panel.drag_hold_role("Target A", Role::BUTTON, other - own);
assert!(drag::mark(panel.ctx()).is_some(), "another row's circle takes the appearance");
panel.frame_with(vec![Event::PointerMoved(own)]);
assert!(drag::mark(panel.ctx()).is_none(), "the circle refuses its own row's appearance");
let history = undo_len(&panel.app());
panel.release();
{
let app = panel.app();
assert_eq!(undo_len(&app), history, "the drop on its own circle makes no edit");
assert!(near(opacity(&app, a), 0.3) && near(opacity(&app, b), 1.0));
}
panel.drag("Target A", "Target B", Modifiers::ALT);
{
let app = panel.app();
assert!(near(opacity(&app, a), 0.3) && near(opacity(&app, b), 0.3), "an Alt drop copies the appearance");
}
panel.app().run("transparency.set", json!({"ids": [a.0], "opacity": 50})).unwrap();
panel.drag("Target A", "Target B", Modifiers::NONE);
let app = panel.app();
assert!(near(opacity(&app, a), 1.0) && near(opacity(&app, b), 0.5), "a plain drop moves the appearance");
}
/// A target circle refuses an appearance carried over from another document: held across Next Document and
/// released on the new document's circle, it leaves the objects with the same IDs there as they were.
#[test]
fn a_target_circle_refuses_an_appearance_from_another_document() {
use crate::panel_drag::PanelDrag;
use crate::tests::panel_harness::Panel;
use craft::ui::contract::Role;
use craft::ui::runtime::drag;
use egui::{Event, Key, Modifiers};
let (app, [a, b]) = two_documents_with_a_styled();
let first = app.session.active().unwrap().uid;
let mut panel = Panel::new(app, show);
let from = panel.rect_role("Target A", Role::BUTTON).center();
let to = panel.rect_role("Target B", Role::BUTTON).center();
panel.drag_hold_role("Target A", Role::BUTTON, to - from);
assert!(drag::mark(panel.ctx()).is_some(), "the circle takes an appearance from its own document");
panel.key(Key::F6, Modifiers::COMMAND);
let history = {
let app = panel.app();
let st = app.session.active().unwrap();
assert_ne!(st.uid, first, "Next Document switches documents during the drag");
st.history.undo.len()
};
let to = panel.rect_role("Target B", Role::BUTTON).center();
panel.frame_with(vec![Event::PointerMoved(to)]);
let carried = drag::active::<PanelDrag>(panel.ctx());
assert!(matches!(carried.as_deref(), Some(PanelDrag::Appearance { document, source, .. }) if *document == first && *source == a));
assert!(drag::mark(panel.ctx()).is_none(), "the circle refuses an appearance from another document");
panel.release();
{
let app = panel.app();
assert!(near(opacity(&app, b), 1.0), "the object with the same ID keeps its look");
assert_eq!(undo_len(&app), history, "the foreign drop makes no edit");
}
panel.drag("Target A", "Target B", Modifiers::NONE);
assert!(near(opacity(&panel.app(), b), 0.3), "a drag within the new document still moves the appearance");
}
/// A target circle takes only an appearance: a paint or the selected art dragged from a panel is refused and
/// leaves the row as it was.
#[test]
fn a_target_circle_refuses_a_paint_and_dragged_art() {
use crate::panel_drag::PanelDrag;
use crate::tests::panel_harness::Panel;
use craft::ui::contract::Role;
use craft::ui::runtime::drag;
let (mut app, _, [a, b]) = two_rects();
name_row(&mut app, a, "A");
name_row(&mut app, b, "B");
app.run("transparency.set", json!({"ids": [a.0], "opacity": 30})).unwrap();
app.run("select.none", json!({})).unwrap();
let mut panel = Panel::new(app, drag_sources_and_layers);
let hold = |panel: &mut Panel, name: &str| {
let from = panel.rect_role(name, Role::LIST_ITEM).center();
let to = panel.rect_role("Target B", Role::BUTTON).center();
panel.drag_hold_role(name, Role::LIST_ITEM, to - from);
drag::active::<PanelDrag>(panel.ctx()).map(|carried| (*carried).clone())
};
for name in ["Dragged paint", "Dragged art"] {
let carried = hold(&mut panel, name);
assert!(matches!(carried, Some(PanelDrag::Paint { .. } | PanelDrag::Art { .. })), "{name} carries its payload");
assert!(drag::mark(panel.ctx()).is_none(), "the circle refuses {name}");
let history = undo_len(&panel.app());
panel.release();
let app = panel.app();
assert_eq!(undo_len(&app), history, "{name} makes no edit");
assert!(near(opacity(&app, b), 1.0), "{name} leaves the row's appearance alone");
}
let carried = hold(&mut panel, "Dragged appearance");
let (document, reverts) = {
let app = panel.app();
let st = app.session.active().unwrap();
(st.uid, st.reverts)
};
assert_eq!(carried, Some(PanelDrag::Appearance { document, reverts, source: a }));
assert!(drag::mark(panel.ctx()).is_some(), "the circle takes an appearance from a panel");
panel.release();
assert!(near(opacity(&panel.app(), b), 0.3), "the dropped appearance moves to the row");
}
/// A target circle's appearance held across File › Revert and dropped on another row's circle
/// leaves the restored objects with the same IDs as they were; a drag started after the revert
/// still moves the appearance.
+1 -1
View File
@@ -2253,7 +2253,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
Fill and stroke paint (Fill, Stroke, None, Apply Last Color and Apply Last Gradient, also on characters selected with the Type tool), the Stroke panel's options, gradient and freeform point edits, Swap Fill and Stroke, Default Fill and Stroke, the Eyedropper, and the Appearance panel's item edits, Clear Appearance, Reduce to Basic Appearance, Remove Item, item reordering and Move Appearance record no undo step when they change nothing.
The Appearance panel's row edits (`appearance.setItem`), Duplicate Item (`appearance.duplicateItem`) and fill and stroke edits aimed at a row (`item`) look up which objects had their shown row written in a set, so that step takes time in step with the number of objects. With 20,000 squares, each with one fill and one stroke row and each command given every square's id, that step takes 0.4 ms of thread CPU time on Linux instead of 57 to 63 ms, and the whole `appearance.setItem` command takes 96 ms instead of 158 ms; at 2,000 objects the difference is about 2 ms (`crates/engine/examples/appearance_rows_bench.rs`; `cmd::graph::tests::row_edits_on_several_labels_keep_the_last_written_shown_row`).
A Stroke panel edit (`stroke.set` with no `item`) checks each object it collects against a set of the objects already listed, so collecting its targets takes time in step with the number of objects, and the list and its order are the same as before. With 20,000 paths in one group, collecting the targets takes 0.66 ms of thread CPU time on Linux, against 55 ms when each object is looked up in the list, and the whole command takes 60 ms (`crates/engine/examples/stroke_targets_bench.rs`; `cmd::stroke::tests::stroke_targets_match_the_listed_merge`).
A Layers panel target circle dropped on the panel's Delete Selection button reduces that layer, group or object to basic appearance (`appearance.reduceToBasic`) in one undo step and deletes nothing, as the [Appearance attributes](https://helpx.adobe.com/illustrator/using/appearance-attributes.html) help page describes for that drag. Which fill and stroke stay (the topmost visible ones), that a layer or group keeps only the rows it had, and that the object's opacity and blend mode stay are VectorCraft's own rules (`panels::layers` test `dropping_a_target_circle_on_the_trash_reduces_it_to_basic_appearance`).
A Layers panel target circle dropped on the panel's Delete Selection button reduces that layer, group or object to basic appearance (`appearance.reduceToBasic`) in one undo step and deletes nothing, as the [Appearance attributes](https://helpx.adobe.com/illustrator/using/appearance-attributes.html) help page describes for that drag. Which fill and stroke stay (the topmost visible ones), that a layer or group keeps only the rows it had, and that the object's opacity and blend mode stay are VectorCraft's own rules (`panels::layers` tests `delete_selection_reduces_a_dropped_appearance_to_basic` and `delete_selection_refuses_an_appearance_from_another_document`).
The Add New Effect popup (Appearance panel, Properties), the Appearance panel's swatch picker, the Gradient panel's gradient swatches menu and the Image Trace button's list of presets stop at the bottom of a short window, and the mouse wheel or the scroll bar reaches their last rows. A list that fits does not scroll (`a_long_swatch_picker_scrolls_inside_a_short_window`).
An image's own fills and strokes draw the shape that a Convert to Shape or Outline Object effect on them gives them (the image's box, or the outline of the image's opaque area or its frame, reshaped by the effects after it), under or over the image as its Contents row says, on the canvas, in exports and through Expand Appearance; new fills and strokes on an image go under it. Without one of those effects they draw nothing, and Use Preview Bounds then measures an image by its frame.
Outline Object on an image's own fill or stroke follows the outline of the image's opaque area, and the image's frame when the image has no transparency. Path effects apply to a fill or stroke added to a bitmap object ([archived reference manual, page 561](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=561)), and with Outline Object such a stroke follows the boundary of the art when the image has transparent areas and the image's frame when it has none ([CreativePro article on strokes for placed images](https://web.archive.org/web/20250815214529/https://creativepro.com/add-strokes-placed-images-illustrator/)). VectorCraft's own rules: the opaque area is the pixels at least 50% opaque, and its outline is traced as Image Trace's Black and White mode traces at threshold 128 and fitted with curves. Evidence: `tests::imageoutline` (vectorcraft-effects), `opaque::tests` (vectorcraft-trace), `tests::containers::an_images_stroke_with_outline_object_follows_its_opaque_area` and `tests::containers::an_images_outline_object_stroke_exports_selects_and_measures_along_its_opaque_area` (vectorcraft-engine), `tests::objectfx::an_images_outline_object_stroke_follows_new_pixels_under_the_same_key` (vectorcraft-render).