diff options
author | Alex Vinyals | 2023-08-09 01:56:55 +0000 |
---|---|---|
committer | GitHub | 2023-08-09 01:56:55 +0000 |
commit | 48eb0d47925586a9dadea577fad607776631b4ab (patch) | |
tree | 515549a7149d8cd2d3664fac22bd59b144533d96 /helix-term/src/commands | |
parent | 294aa669a24ce10e5af32d2447f677bf6edd36d0 (diff) |
Enhance :toggle to support cycling numbers (#7877)
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r-- | helix-term/src/commands/typed.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 5bb9c6c4..463bce25 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -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 |