@@ -1271,9 +1271,6 @@ pub mod insert {
1271 pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
1271 pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
1272 pub type PostHook = fn(&mut Context, char);
1272 pub type PostHook = fn(&mut Context, char);
1274− use helix_core::auto_pairs;
1275− const HOOKS: &[Hook] = &[auto_pairs::hook];
1277 fn completion(cx: &mut Context, ch: char) {
1274 fn completion(cx: &mut Context, ch: char) {
1278 // if ch matches completion char, trigger completion
1275 // if ch matches completion char, trigger completion
1279 let doc = cx.doc();
1276 let doc = cx.doc();
@@ -1302,7 +1299,6 @@ pub mod insert {
1305− // TODO: the pre-hook handles ( so post hook never gets called
1306 fn signature_help(cx: &mut Context, ch: char) {
1302 fn signature_help(cx: &mut Context, ch: char) {
1307 // if ch matches signature_help char, trigger
1303 // if ch matches signature_help char, trigger
1308 let doc = cx.doc();
1304 let doc = cx.doc();
@@ -1330,27 +1326,35 @@ pub mod insert {
1330 super::signature_help(cx);
1326 super::signature_help(cx);
1330+ // 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) }
1333+ // The default insert hook: simply insert the character
1334+ fn insert(doc: &Rope, selection: &Selection, ch: char) -> Option<Transaction> {
1335+ let t = Tendril::from_char(ch);
1336+ let transaction = Transaction::insert(doc, selection, t);
1340+ use helix_core::auto_pairs;
1341+ const HOOKS: &[Hook] = &[auto_pairs::hook, insert];
1335 const POST_HOOKS: &[PostHook] = &[completion, signature_help];
1342 const POST_HOOKS: &[PostHook] = &[completion, signature_help];
1337− // TODO: insert means add text just before cursor, on exit we should be on the last letter.
1338 pub fn insert_char(cx: &mut Context, c: char) {
1344 pub fn insert_char(cx: &mut Context, c: char) {
1339 let (view, doc) = cx.current();
1345 let (view, doc) = cx.current();
1347+ let text = doc.text();
1348+ let selection = doc.selection(view.id);
1341 // run through insert hooks, stopping on the first one that returns Some(t)
1350 // run through insert hooks, stopping on the first one that returns Some(t)
1342 for hook in HOOKS {
1351 for hook in HOOKS {
1343− if let Some(transaction) = hook(doc.text(), doc.selection(view.id), c) {
1352+ if let Some(transaction) = hook(text, selection, c) {
1344 doc.apply(&transaction, view.id);
1353 doc.apply(&transaction, view.id);
1345− return;
1354+ break;
1349− let t = Tendril::from_char(c);
1350− let transaction = Transaction::insert(doc.text(), doc.selection(view.id), t);
1352− doc.apply(&transaction, view.id);
1354 // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
1358 // TODO: need a post insert hook too for certain triggers (autocomplete, signature help, etc)
1355 // this could also generically look at Transaction, but it's a bit annoying to look at
1359 // this could also generically look at Transaction, but it's a bit annoying to look at
1356 // Operation instead of Change.
1360 // Operation instead of Change.