aboutsummaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorSkyler Hawthorne2021-12-13 15:58:58 +0000
committerGitHub2021-12-13 15:58:58 +0000
commit94535fa013469abf6e5ab2fa52f3deced9d46de0 (patch)
treed72a251abe1dfae3ff50136b5b8413c835a2b629 /helix-term
parent730d3be2010adbd2c43b7cdf1a256a15ef97e3f2 (diff)
Add auto pairs for same-char pairs (#1219)
* Add auto pairs for same-char pairs * Add unit tests for all existing functionality * Add auto pairs for same-char pairs (quotes, etc). Account for apostrophe in prose by requiring both sides of the cursor to be non-pair chars or whitespace. This also incidentally will work for avoiding a double single quote in lifetime annotations, at least until <> is added * Slight factor of moving the cursor transform of the selection to inside the hooks. This will enable doing auto pairing with selections, and fixing the bug where auto pairs destroy the selection. Fixes #1014
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 22c23043..8552f638 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -4199,8 +4199,9 @@ pub mod insert {
// The default insert hook: simply insert the character
#[allow(clippy::unnecessary_wraps)] // need to use Option<> because of the Hook signature
fn insert(doc: &Rope, selection: &Selection, ch: char) -> Option<Transaction> {
+ let cursors = selection.clone().cursors(doc.slice(..));
let t = Tendril::from_char(ch);
- let transaction = Transaction::insert(doc, selection, t);
+ let transaction = Transaction::insert(doc, &cursors, t);
Some(transaction)
}
@@ -4215,11 +4216,11 @@ pub mod insert {
};
let text = doc.text();
- let selection = doc.selection(view.id).clone().cursors(text.slice(..));
+ 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(text, &selection, c) {
+ if let Some(transaction) = hook(text, selection, c) {
doc.apply(&transaction, view.id);
break;
}