mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 19:51:26 -05:00
Plug-ins: a file placed during an add-on preview survives Cancel
With an add-on dialog previewing (Arrange in Grid, for example), File > Place ran inside the preview's interaction, because every `file.*` command other than `file.documentColorMode` was treated as one that reads the drawing on show. The placed art went into the preview document with no undo step of its own, and Cancel removed it. `file.place` now runs on the document without the preview, as other edits do: it records its own undo step and stays after Cancel and OK. Save, Export, Copy and the other `file.*` commands still act on the drawing as the preview shows it. Docs: docs/mcp.md (undo/redo row).
This commit is contained in:
@@ -1004,9 +1004,10 @@ fn take_changed_paints(
|
||||
}
|
||||
|
||||
/// Whether command `id` acts on the drawing as a dialog's preview shows it (a copy, a save, a
|
||||
/// revert), so it runs inside that preview rather than as a step of its own.
|
||||
/// revert), so it runs inside that preview rather than as a step of its own. Place adds art, so
|
||||
/// it runs on the document without the preview, as other edits do.
|
||||
fn reads_preview(id: &str) -> bool {
|
||||
id == "edit.copy" || (id.starts_with("file.") && id != "file.documentColorMode")
|
||||
id == "edit.copy" || (id.starts_with("file.") && id != "file.documentColorMode" && id != "file.place")
|
||||
}
|
||||
|
||||
/// The selection on show in a dialog's preview `shown`, as a command from outside the dialog acts
|
||||
|
||||
@@ -488,6 +488,30 @@ fn an_add_on_preview_keeps_an_edit_made_outside_the_dialog() {
|
||||
assert_eq!(undo_len(&app), undo + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_add_on_preview_keeps_a_file_placed_outside_the_dialog() {
|
||||
let dir = std::env::temp_dir().join(format!("vectorcraft-addon-place-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("placed.vectorcraft");
|
||||
std::fs::write(&path, vectorcraft_format::save_file(&vectorcraft_doc::Document::new(80.0, 40.0))).unwrap();
|
||||
let mut app = two_rects();
|
||||
open_item(&mut app, "Arrange Tools", "Arrange in Grid…");
|
||||
let id = dialog_id(&app);
|
||||
set(&app, id, "layout", json!("row"));
|
||||
set(&app, id, "preview", json!(true));
|
||||
frame(&mut app);
|
||||
assert_eq!(x0(&app, 1), 30.0, "previewed");
|
||||
let undo = undo_len(&app);
|
||||
app.run("file.place", json!({"path": path.to_string_lossy(), "at": [300, 300]})).unwrap();
|
||||
std::fs::remove_dir_all(&dir).unwrap();
|
||||
assert_eq!(undo_len(&app), undo + 1, "the placed file is a step of its own");
|
||||
cancel(&app, id);
|
||||
frame(&mut app);
|
||||
assert!(!app.session.in_interaction());
|
||||
assert_eq!(count(&app), 3, "Cancel keeps the placed file");
|
||||
assert_eq!(x0(&app, 1), 100.0, "Cancel rolls the preview back");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_add_on_preview_waits_for_its_opening_drawing() {
|
||||
let mut app = two_drawings();
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user