mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:42:44 +00:00
Name the undo step when keeping an add-on preview
This commit is contained in:
@@ -99,8 +99,8 @@ fn pump_commit(app: &mut VectorcraftApp) {
|
||||
let live = host.with(|h| h.get_mut_by_id::<HostedParamDialog>(id).map(|d| (d.is_previewing(), (spec.params)(d.fields()))));
|
||||
if let Some((previewing, params)) = &live {
|
||||
let mut preview = mem::take(&mut app.addon_dialogs.preview);
|
||||
// PLAN: the undo step's label is the command id; `Spec` carries no heading (wg.A20 takes a label)
|
||||
let answer = preview.run(app, *previewing, spec.command, spec.command, params);
|
||||
let label = vectorcraft_engine::find_command(spec.command).map_or(spec.command, |command| command.label);
|
||||
let answer = preview.run(app, *previewing, label, spec.command, params);
|
||||
app.addon_dialogs.preview = preview;
|
||||
if let (Some(found), Some(answer)) = (spec.found, answer) {
|
||||
host.with(|h| {
|
||||
|
||||
@@ -247,6 +247,25 @@ fn add_on_dialogs_preview_cancel_and_run_their_command() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeping_an_add_on_preview_records_the_command_name() {
|
||||
let mut app = two_rects();
|
||||
let undo = undo_len(&app);
|
||||
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");
|
||||
assert_eq!(undo_len(&app), undo, "the preview is still temporary");
|
||||
|
||||
assert!(confirm(&app, id));
|
||||
frame(&mut app);
|
||||
let history = &app.session.doc().unwrap().history;
|
||||
assert_eq!(history.undo.len(), undo + 1);
|
||||
assert_eq!(history.undo.last().unwrap().label, "Arrange in Grid");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_a_second_add_on_dialog_closes_the_first_and_rolls_back_its_preview() {
|
||||
let mut app = two_rects();
|
||||
|
||||
Reference in New Issue
Block a user