mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix(layers): keep group-nested names out of the Layer N counter
#17366 marks numbered layers inside groups as not measured, and an unmeasured case keeps today's behaviour: with a group holding "Layer 7" the suggestion is "Layer 1" today, but the first cut of `next_layer_suggestion` counted every layer and lifted it to "Layer 8". The counter now reads top-level names only, the reading #14821 chose for the Layer from Background search, pinned by `a_numbered_layer_inside_a_group_does_not_count`. Fixes #17366
This commit is contained in:
1 parent
2025c854d2
commit
f6fa121cd2
2 files changed
+26
-7
No files matched your search
@@ -1378,12 +1378,14 @@ impl Document {
|
||||
}
|
||||
|
||||
/// The "Layer N" a new plain layer is suggested: N is one above the highest number among the
|
||||
/// names that are exactly "Layer <number>", or 1 when no layer has such a name (#17365). Only
|
||||
/// Layer > New > Layer and its dialog use this; other callers keep [`Self::next_layer_name`].
|
||||
/// Names are gathered as `next_layer_name` gathers them (every layer, compared exactly), and a
|
||||
/// number too large to hold is not counted, like a name that is not "Layer <number>".
|
||||
/// top-level names that are exactly "Layer <number>", or 1 when no top-level layer has such a
|
||||
/// name (#17365). Only Layer > New > Layer and its dialog use this; other callers keep
|
||||
/// [`Self::next_layer_name`]. Top-level names only, compared exactly, the reading the Layer
|
||||
/// from Background rule chose for its search (#14821): whether numbered layers inside groups
|
||||
/// count is not measured in #17366, so nested names stay out of it. A number too large to hold
|
||||
/// is not counted, like a name that is not "Layer <number>".
|
||||
pub fn next_layer_suggestion(&self) -> String {
|
||||
let highest = self.walk().into_iter().filter_map(|(_, _, l)| l.name.strip_prefix("Layer ")).filter_map(|digits| digits.parse::<u64>().ok()).max();
|
||||
let highest = self.layers.iter().filter_map(|l| l.name.strip_prefix("Layer ")).filter_map(|digits| digits.parse::<u64>().ok()).max();
|
||||
format!("Layer {}", highest.unwrap_or(0).saturating_add(1))
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
//! `crates/ui-egui/src/dialogs/new_layer_ui.rs` pins that the prefilled name equals the name the
|
||||
//! command gives, by behaviour rather than by naming one function twice.
|
||||
//!
|
||||
//! Not measured in the issue: whether numbered layers inside groups count. Names are gathered as
|
||||
//! `Document::next_layer_name` gathers them today: every layer in the document, compared exactly.
|
||||
//! Not measured in the issue: whether numbered layers inside groups count. They keep today's
|
||||
//! suggestion: the counter reads top-level names only, the reading the merged Layer from
|
||||
//! Background rule chose for its own search (#14821), pinned by
|
||||
//! `a_numbered_layer_inside_a_group_does_not_count`.
|
||||
//! Layer from Background keeps its own measured lowest-free rule (#14821), pinned below.
|
||||
|
||||
use photocraft_doc::LayerId;
|
||||
@@ -67,6 +69,21 @@ fn names_that_are_not_exactly_layer_number_do_not_count() {
|
||||
assert_eq!(default_name(&others), "Layer 1", "only exact \"Layer <number>\" names count");
|
||||
}
|
||||
|
||||
/// Not measured in #17366: numbered layers inside groups. They keep today's suggestion, taking the
|
||||
/// top-level reading the sibling Layer from Background rule chose (#14821): a group holding
|
||||
/// "Layer 7" leaves the default at "Layer 1", where today's first-free rule lands as well.
|
||||
#[test]
|
||||
fn a_numbered_layer_inside_a_group_does_not_count() {
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
s.execute("layer.new.group", json!({ "name": "G" })).unwrap();
|
||||
// A fresh group is open, so this layer lands inside it (see layer_place_tests).
|
||||
let nested = LayerId(s.execute("layer.new.layer", json!({ "name": "Layer 7" })).unwrap()["layer"].as_u64().unwrap());
|
||||
assert_eq!(doc(&s).path_of(nested).map(|p| p.len()), Some(2), "Layer 7 sits inside the group");
|
||||
let made = LayerId(s.execute("layer.new.layer", json!({})).unwrap()["layer"].as_u64().unwrap());
|
||||
assert_eq!(doc(&s).layer(made).unwrap().name, "Layer 1", "the nested Layer 7 does not lift the suggestion");
|
||||
}
|
||||
|
||||
/// #14821 measured Layer from Background as its own lowest-free rule, counting from 0. The shared
|
||||
/// counter must not change what that command names the converted Background.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user