Skip to content

Commit

Permalink
Always retain the first (default) layer
Browse files Browse the repository at this point in the history
  • Loading branch information
madig committed Mar 11, 2024
1 parent a9cafdb commit 0b9e433
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,15 @@ impl LayerContents {
where
F: FnMut(&Layer) -> bool,
{
self.layers.retain(|layer| layer.name == DEFAULT_LAYER_NAME || predicate(layer))
// Always keep the default layer, which is always the first.
let mut is_first = true;
self.layers.retain(|layer| {
if is_first {
is_first = false;
return true;
}
predicate(layer)
});
}

/// Removes any layers that contain no glyphs
Expand Down Expand Up @@ -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::<Vec<_>>();
assert_eq!(names.as_slice(), &[DEFAULT_LAYER_NAME, "fizz", "fizzbuzz"]);
assert_eq!(names.as_slice(), &["foreground", "fizz", "fizzbuzz"]);
}

#[test]
Expand Down

0 comments on commit 0b9e433

Please sign in to comment.