diff options
author | Blaž Hrastnik | 2021-05-03 08:56:02 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-05-03 08:56:02 +0000 |
commit | ab4decfd6d18ee7377e20741d207e9e7b77758f4 (patch) | |
tree | 8e4b1fa8268e3e17fd08d52692fde20d7af1a33a | |
parent | b0bdcab97095f9611990211cef679d8a5a05116c (diff) |
Make post hooks trigger even when a different handler processes input.
The default handler is now simply a fallback.
-rw-r--r-- | TODO.md | 5 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 28 |
2 files changed, 16 insertions, 17 deletions
@@ -42,13 +42,8 @@ - [ ] lsp: formatting - [x] lsp: goto -- [ ] search: wrap around file - [ ] search: smart case by default: insensitive unless upper detected -- decide if markdown should have vertical padding too - -- the hooks system should be better for pre/post insert. - 2 - [ ] surround bindings (select + surround ( wraps selection in parens ) - [ ] macro recording diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b77e205f..bd65688d 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1271,9 +1271,6 @@ pub mod insert { pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>; pub type PostHook = fn(&mut Context, char); - use helix_core::auto_pairs; - const HOOKS: &[Hook] = &[auto_pairs::hook]; - fn completion(cx: &mut Context, ch: char) { // if ch matches completion char, trigger completion let doc = cx.doc(); @@ -1302,7 +1299,6 @@ pub mod insert { } } - // TODO: the pre-hook handles ( so post hook never gets called fn signature_help(cx: &mut Context, ch: char) { // if ch matches signature_help char, trigger let doc = cx.doc(); @@ -1330,27 +1326,35 @@ pub mod insert { super::signature_help(cx); } } + + // 2021-05-03T17:54:36.326 hx::commands [INFO] SignatureHelp { signatures: [SignatureInformation { label: "fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error>", documentation: None, parameters: Some([ParameterInformation { label: Simple("path: PathBuf"), documentation: None }, ParameterInformation { label: Simple("action: Action"), documentation: None }]), active_parameter: Some(0) }], active_signature: None, active_parameter: Some(0) } } + // The default insert hook: simply insert the character + fn insert(doc: &Rope, selection: &Selection, ch: char) -> Option<Transaction> { + let t = Tendril::from_char(ch); + let transaction = Transaction::insert(doc, selection, t); + Some(transaction) + } + + use helix_core::auto_pairs; + const HOOKS: &[Hook] = &[auto_pairs::hook, insert]; const POST_HOOKS: &[PostHook] = &[completion, signature_help]; - // TODO: insert means add text just before cursor, on exit we should be on the last letter. pub fn insert_char(cx: &mut Context, c: char) { let (view, doc) = cx.current(); + let text = doc.text(); + let selection = doc.selection(view.id); + // run through insert hooks, stopping on the first one that returns Some(t) for hook in HOOKS { - if let Some(transaction) = hook(doc.text(), doc.selection(view.id), c) { + if let Some(transaction) = hook(text, selection, c) { doc.apply(&transaction, view.id); - return; + break; } } - let t = Tendril::from_char(c); - let transaction = Transaction::insert(doc.text(), doc.selection(view.id), t); - - doc.apply(&transaction, view.id); - // 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. |