diff --git a/src/layer.rs b/src/layer.rs index a63d54ff..ea9a3464 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -237,7 +237,7 @@ impl LayerContents { where F: FnMut(&Layer) -> bool, { - self.layers.retain(|layer| layer.name == DEFAULT_LAYER_NAME || predicate(layer)) + self.layers.retain(|layer| layer.is_default() || predicate(layer)); } /// Removes any layers that contain no glyphs @@ -452,6 +452,14 @@ impl Layer { self.glyphs.is_empty() } + /// Returns `true` if this layer is the default layer. + /// + /// The default layer can have any name, but always uses the "glyphs" + /// directory. + pub fn is_default(&self) -> bool { + self.path == Path::new(DEFAULT_GLYPHS_DIRNAME) + } + /// Returns the name of the layer. /// /// This can only be mutated through the [`LayerContents`]. @@ -904,12 +912,13 @@ mod tests { ], ..Default::default() }; + layers.rename_layer("public.default", "foreground", false).unwrap(); layers.retain(|l| l.name().starts_with("fizz")); assert_eq!(layers.len(), 3, "wrong number of layers deleted"); let names = layers.iter().map(|l| l.name().as_str()).collect::>(); - assert_eq!(names.as_slice(), &[DEFAULT_LAYER_NAME, "fizz", "fizzbuzz"]); + assert_eq!(names.as_slice(), &["foreground", "fizz", "fizzbuzz"]); } #[test]