Skip to content

Commit

Permalink
Enhance :toggle to support cycling numbers (helix-editor#7877)
Browse files Browse the repository at this point in the history
  • Loading branch information
alevinval authored and mtoohey31 committed Jun 2, 2024
1 parent 826dde7 commit 58d4952
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1856,14 +1856,29 @@ fn toggle_option(
.to_string(),
)
}
Value::Null | Value::Object(_) | Value::Array(_) | Value::Number(_) => {
Value::Number(ref value) => {
ensure!(
args.len() > 2,
"Bad arguments. For number configurations use: `:toggle key val1 val2 ...`",
);

Value::Number(
args[1..]
.iter()
.skip_while(|&e| value.to_string() != *e.to_string())
.nth(1)
.unwrap_or_else(|| &args[1])
.parse()?,
)
}
Value::Null | Value::Object(_) | Value::Array(_) => {
anyhow::bail!("Configuration {key} does not support toggle yet")
}
};

let status = format!("'{key}' is now set to {value}");
let config = serde_json::from_value(config)
.map_err(|_| anyhow::anyhow!("Could not parse field: `{:?}`", &args))?;
.map_err(|err| anyhow::anyhow!("Cannot parse `{:?}`, {}", &args, err))?;

cx.editor
.config_events
Expand Down

0 comments on commit 58d4952

Please sign in to comment.