Skip to content

Commit

Permalink
make :toggle-option print the new value (#6774)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
  • Loading branch information
zummenix and the-mikedavis authored Apr 16, 2023
1 parent 7607727 commit 7706ff7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,12 +1770,12 @@ fn toggle_option(
let pointer = format!("/{}", key.replace('.', "/"));
let value = config.pointer_mut(&pointer).ok_or_else(key_error)?;

if let Value::Bool(b) = *value {
*value = Value::Bool(!b);
} else {
let Value::Bool(old_value) = *value else {
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
// with another, maintaining a valid json config
let config = serde_json::from_value(config).unwrap();
Expand All @@ -1784,6 +1784,8 @@ fn toggle_option(
.config_events
.0
.send(ConfigEvent::Update(config))?;
cx.editor
.set_status(format!("Option `{}` is now set to `{}`", key, new_value));
Ok(())
}

Expand Down

0 comments on commit 7706ff7

Please sign in to comment.