diff options
author | lurpahi | 2021-09-24 01:28:44 +0000 |
---|---|---|
committer | GitHub | 2021-09-24 01:28:44 +0000 |
commit | a958d34bfbcf45c01ce0d9c0d76e681fb863fc6a (patch) | |
tree | 7993d194fafd1d32806538fe34292b6ae37429b8 /helix-term/src/commands.rs | |
parent | 432bec10eddb3f51f3a6e32aedbfd566d74cde75 (diff) |
Add option for automatic insertion of closing-parens/brackets/etc (#779)
* Add auto-pair editor option
* Document auto-pair editor option
* Make cargo fmt happy
* Actually make cargo fmt happy
* Rename auto-pair option to auto-pairs
* Inline a few constants
Co-authored-by: miaomai <cunso@tutanota.com>
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index ac93b5d0..117ba046 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3371,17 +3371,20 @@ pub mod insert { } use helix_core::auto_pairs; - const HOOKS: &[Hook] = &[auto_pairs::hook, insert]; - const POST_HOOKS: &[PostHook] = &[completion, signature_help]; pub fn insert_char(cx: &mut Context, c: char) { let (view, doc) = current!(cx.editor); + let hooks: &[Hook] = match cx.editor.config.auto_pairs { + true => &[auto_pairs::hook, insert], + false => &[insert], + }; + let text = doc.text(); let selection = doc.selection(view.id).clone().cursors(text.slice(..)); // run through insert hooks, stopping on the first one that returns Some(t) - for hook in HOOKS { + for hook in hooks { if let Some(transaction) = hook(text, &selection, c) { doc.apply(&transaction, view.id); break; @@ -3391,7 +3394,7 @@ pub mod insert { // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc) // this could also generically look at Transaction, but it's a bit annoying to look at // Operation instead of Change. - for hook in POST_HOOKS { + for hook in &[completion, signature_help] { hook(cx, c); } } |