Keep applied guide layouts visible after preview closes (#5084)

Co-authored-by: jonathnwxh <258340642+jonathanwxh-cell@users.noreply.github.com>
This commit is contained in:
jonathanwxh-cell 2026-10-14 00:03:16 +08:00 committed by GitHub
parent 35710a94ad
commit f20605219e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 55 additions and 0 deletions

View File

@ -157,6 +157,10 @@ pub fn confirm(app: &mut PhotocraftApp, f: &Map<String, Value>) -> Result<Value,
let color = rgb(color).ok_or("invalid guide color")?;
let hex = format!("#{:02x}{:02x}{:02x}", color.r(), color.g(), color.b());
let result = app.run(COMMAND, params(f))?;
// The preview is visible even when guides were hidden. Keep a committed layout visible too.
app.ui.view.extras = true;
app.ui.view.show.canvas_guides = true;
app.ui.extras.guides = true;
app.session.prefs.edit(|prefs| prefs.guides_grid_and_slices.guide_color = hex);
let mut remembered = f.clone();
for key in [MARK, "__command", "__label", "__document", "__previewGuides", "__previewParams", "__previewSource"] {

View File

@ -1,5 +1,56 @@
use super::*;
#[test]
fn applying_a_previewed_layout_reveals_hidden_guides() {
for hidden in ["extras", "canvas", "guides"] {
let mut app = app();
match hidden {
"extras" => app.ui.view.extras = false,
"canvas" => app.ui.view.show.canvas_guides = false,
_ => app.ui.extras.guides = false,
}
let id = open(&mut app);
let doc = &app.session.active().unwrap().doc;
assert!(preview(&app, doc).is_some(), "the dialog shows a preview despite hidden {hidden}");
crate::dialogs::confirm(&mut app, id).unwrap();
let doc = &app.session.active().unwrap().doc;
assert!(!doc.guides.vertical.is_empty(), "the layout was actually created");
assert!(preview(&app, doc).is_none(), "the temporary preview is gone");
assert!(app.ui.view.shows(app.ui.view.show.canvas_guides) && app.ui.extras.guides, "applied guides must remain visible when {hidden} was hidden");
}
}
#[test]
fn cancelling_invalid_and_empty_layouts_keep_guides_hidden() {
for action in ["cancel", "invalid", "empty"] {
let mut app = app();
app.ui.view.extras = false;
app.ui.view.show.canvas_guides = false;
app.ui.extras.guides = false;
let id = open(&mut app);
match action {
"cancel" => {
crate::dialogs::cancel(&mut app, id).unwrap();
}
"invalid" => {
app.ui.dialog_mut(id).unwrap().fields.insert("color".into(), json!("invalid"));
assert!(crate::dialogs::confirm(&mut app, id).is_err());
}
_ => {
let f = &mut app.ui.dialog_mut(id).unwrap().fields;
for key in ["__columnsEnabled", "__rowsEnabled", "__marginEnabled"] {
f.insert(key.into(), json!(false));
}
f.insert("clearExisting".into(), json!(true));
assert!(crate::dialogs::confirm(&mut app, id).is_err(), "an empty layout is rejected");
}
}
let guides = &app.session.active().unwrap().doc.guides;
assert!(guides.vertical.is_empty() && guides.horizontal.is_empty(), "{action}");
assert!(!app.ui.view.extras && !app.ui.view.show.canvas_guides && !app.ui.extras.guides, "{action} must not change visibility");
}
}
#[test]
fn tab_includes_optional_sizes_and_shift_tab_selects_their_text() {
let mut app = app();