|
|
@ -1770,12 +1770,12 @@ fn toggle_option(
|
|
|
|
let pointer = format!("/{}", key.replace('.', "/"));
|
|
|
|
let pointer = format!("/{}", key.replace('.', "/"));
|
|
|
|
let value = config.pointer_mut(&pointer).ok_or_else(key_error)?;
|
|
|
|
let value = config.pointer_mut(&pointer).ok_or_else(key_error)?;
|
|
|
|
|
|
|
|
|
|
|
|
if let Value::Bool(b) = *value {
|
|
|
|
let Value::Bool(old_value) = *value else {
|
|
|
|
*value = Value::Bool(!b);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
anyhow::bail!("Key `{}` is not toggle-able", key)
|
|
|
|
anyhow::bail!("Key `{}` is not toggle-able", key)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let new_value = !old_value;
|
|
|
|
|
|
|
|
*value = Value::Bool(new_value);
|
|
|
|
// This unwrap should never fail because we only replace one boolean value
|
|
|
|
// This unwrap should never fail because we only replace one boolean value
|
|
|
|
// with another, maintaining a valid json config
|
|
|
|
// with another, maintaining a valid json config
|
|
|
|
let config = serde_json::from_value(config).unwrap();
|
|
|
|
let config = serde_json::from_value(config).unwrap();
|
|
|
@ -1784,6 +1784,8 @@ fn toggle_option(
|
|
|
|
.config_events
|
|
|
|
.config_events
|
|
|
|
.0
|
|
|
|
.0
|
|
|
|
.send(ConfigEvent::Update(config))?;
|
|
|
|
.send(ConfigEvent::Update(config))?;
|
|
|
|
|
|
|
|
cx.editor
|
|
|
|
|
|
|
|
.set_status(format!("Option `{}` is now set to `{}`", key, new_value));
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|