Better logic for copying themed player colors into registry (#7867)
Release Notes: - Fixed a potential panic when themes did not contain enough player colors ([#7733](https://github.com/zed-industries/zed/issues/7733)). Thanks to @maxdeviant for the code review and improvements!
This commit is contained in:
parent
bf1bcd027c
commit
94426c4393
1 changed files with 28 additions and 24 deletions
|
@ -118,30 +118,34 @@ impl ThemeRegistry {
|
||||||
AppearanceContent::Dark => PlayerColors::dark(),
|
AppearanceContent::Dark => PlayerColors::dark(),
|
||||||
};
|
};
|
||||||
if !user_theme.style.players.is_empty() {
|
if !user_theme.style.players.is_empty() {
|
||||||
player_colors = PlayerColors(
|
for (idx, player) in user_theme.style.players.clone().into_iter().enumerate() {
|
||||||
user_theme
|
let cursor = player
|
||||||
.style
|
.cursor
|
||||||
.players
|
.as_ref()
|
||||||
.into_iter()
|
.and_then(|color| try_parse_color(&color).ok());
|
||||||
.map(|player| PlayerColor {
|
let background = player
|
||||||
cursor: player
|
.background
|
||||||
.cursor
|
.as_ref()
|
||||||
.as_ref()
|
.and_then(|color| try_parse_color(&color).ok());
|
||||||
.and_then(|color| try_parse_color(&color).ok())
|
let selection = player
|
||||||
.unwrap_or_default(),
|
.selection
|
||||||
background: player
|
.as_ref()
|
||||||
.background
|
.and_then(|color| try_parse_color(&color).ok());
|
||||||
.as_ref()
|
|
||||||
.and_then(|color| try_parse_color(&color).ok())
|
if let Some(player_color) = player_colors.0.get_mut(idx) {
|
||||||
.unwrap_or_default(),
|
*player_color = PlayerColor {
|
||||||
selection: player
|
cursor: cursor.unwrap_or(player_color.cursor),
|
||||||
.selection
|
background: background.unwrap_or(player_color.background),
|
||||||
.as_ref()
|
selection: selection.unwrap_or(player_color.selection),
|
||||||
.and_then(|color| try_parse_color(&color).ok())
|
};
|
||||||
.unwrap_or_default(),
|
} else {
|
||||||
})
|
player_colors.0.push(PlayerColor {
|
||||||
.collect(),
|
cursor: cursor.unwrap_or_default(),
|
||||||
);
|
background: background.unwrap_or_default(),
|
||||||
|
selection: selection.unwrap_or_default(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut syntax_colors = match user_theme.appearance {
|
let mut syntax_colors = match user_theme.appearance {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue