aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-22 03:18:48 +0000
committerBlaž Hrastnik2021-03-22 03:22:33 +0000
commit71999cce43b3750362cdea534c12cbf320d2677b (patch)
treeee0ce3fcc192e1d85861b08442109125415b8df0 /helix-term
parenta32806b4901dfbb85fdc6c043515033afcbdb9a7 (diff)
Implement auto-pairs behavior for open and close.
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 54fea453..f7e137e0 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1009,9 +1009,23 @@ pub fn goto_reference(cx: &mut Context) {
// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
pub mod insert {
use super::*;
+ pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
+
+ use helix_core::auto_pairs;
+ const HOOKS: &[Hook] = &[auto_pairs::hook];
+
// 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 doc = cx.doc();
+
+ // 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(), c) {
+ doc.apply(&transaction);
+ return;
+ }
+ }
+
let c = Tendril::from_char(c);
let transaction = Transaction::insert(doc.text(), doc.selection(), c);
@@ -1019,6 +1033,7 @@ pub mod insert {
}
pub fn insert_tab(cx: &mut Context) {
+ // TODO: tab should insert either \t or indent width spaces
insert_char(cx, '\t');
}