Skip to content

Commit

Permalink
Correctly reload theme on :config-reload
Browse files Browse the repository at this point in the history
The current implementation didn't reload the theme if no no theme was
explicitly configured (so the default theme was used). This commit
brings `refresh_theme` in line with the initialization code.
  • Loading branch information
pascalkuthe authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 1725737 commit 4a144a6
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,23 @@ impl Application {

/// Refresh theme after config change
fn refresh_theme(&mut self, config: &Config) -> Result<(), Error> {
if let Some(theme) = config.theme.clone() {
let true_color = self.true_color();
let theme = self
.theme_loader
.load(&theme)
.map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?;

if true_color || theme.is_16_color() {
self.editor.set_theme(theme);
} else {
anyhow::bail!("theme requires truecolor support, which is not available")
}
}
let true_color = config.editor.true_color || crate::true_color();
let theme = config
.theme
.as_ref()
.and_then(|theme| {
self.theme_loader
.load(theme)
.map_err(|e| {
log::warn!("failed to load theme `{}` - {}", theme, e);
e
})
.ok()
.filter(|theme| (true_color || theme.is_16_color()))
})
.unwrap_or_else(|| self.theme_loader.default_theme(true_color));

self.editor.set_theme(theme);
Ok(())
}

Expand All @@ -435,10 +438,6 @@ impl Application {
}
}

fn true_color(&self) -> bool {
self.config.load().editor.true_color || crate::true_color()
}

#[cfg(windows)]
// no signal handling available on windows
pub async fn handle_signals(&mut self, _signal: ()) {}
Expand Down

0 comments on commit 4a144a6

Please sign in to comment.