Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance :toggle to support cycling numbers #7877

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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