|
|
@ -397,40 +397,51 @@ impl Application {
|
|
|
|
self.editor.refresh_config();
|
|
|
|
self.editor.refresh_config();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// refresh language config after config change
|
|
|
|
|
|
|
|
fn refresh_language_config(&mut self) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let syntax_config = helix_core::config::user_syntax_loader()
|
|
|
|
|
|
|
|
.map_err(|err| anyhow::anyhow!("Failed to load language config: {}", err))?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.syn_loader = std::sync::Arc::new(syntax::Loader::new(syntax_config));
|
|
|
|
|
|
|
|
for document in self.editor.documents.values_mut() {
|
|
|
|
|
|
|
|
document.detect_language(self.syn_loader.clone());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Refresh theme after config change
|
|
|
|
/// Refresh theme after config change
|
|
|
|
fn refresh_theme(&mut self, config: &Config) {
|
|
|
|
fn refresh_theme(&mut self, config: &Config) -> Result<(), Error> {
|
|
|
|
if let Some(theme) = config.theme.clone() {
|
|
|
|
if let Some(theme) = config.theme.clone() {
|
|
|
|
let true_color = self.true_color();
|
|
|
|
let true_color = self.true_color();
|
|
|
|
match self.theme_loader.load(&theme) {
|
|
|
|
let theme = self
|
|
|
|
Ok(theme) => {
|
|
|
|
.theme_loader
|
|
|
|
|
|
|
|
.load(&theme)
|
|
|
|
|
|
|
|
.map_err(|err| anyhow::anyhow!("Failed to load theme `{}`: {}", theme, err))?;
|
|
|
|
|
|
|
|
|
|
|
|
if true_color || theme.is_16_color() {
|
|
|
|
if true_color || theme.is_16_color() {
|
|
|
|
self.editor.set_theme(theme);
|
|
|
|
self.editor.set_theme(theme);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
self.editor
|
|
|
|
anyhow::bail!("theme requires truecolor support, which is not available")
|
|
|
|
.set_error("theme requires truecolor support, which is not available");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(err) => {
|
|
|
|
|
|
|
|
let err_string = format!("failed to load theme `{}` - {}", theme, err);
|
|
|
|
|
|
|
|
self.editor.set_error(err_string);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn refresh_config(&mut self) {
|
|
|
|
fn refresh_config(&mut self) {
|
|
|
|
match Config::load_default() {
|
|
|
|
let mut refresh_config = || -> Result<(), Error> {
|
|
|
|
Ok(config) => {
|
|
|
|
let default_config = Config::load_default()
|
|
|
|
self.refresh_theme(&config);
|
|
|
|
.map_err(|err| anyhow::anyhow!("Failed to load config: {}", err))?;
|
|
|
|
|
|
|
|
self.refresh_language_config()?;
|
|
|
|
|
|
|
|
self.refresh_theme(&default_config)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Store new config
|
|
|
|
if let Err(err) = refresh_config() {
|
|
|
|
self.config.store(Arc::new(config));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(err) => {
|
|
|
|
|
|
|
|
self.editor.set_error(err.to_string());
|
|
|
|
self.editor.set_error(err.to_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn true_color(&self) -> bool {
|
|
|
|
fn true_color(&self) -> bool {
|
|
|
|
self.config.load().editor.true_color || crate::true_color()
|
|
|
|
self.config.load().editor.true_color || crate::true_color()
|
|
|
|