aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-04-22 14:26:57 +0000
committerBlaž Hrastnik2021-04-22 14:26:57 +0000
commit7e9ea30a0b4eee08322d689450efebe74dec8097 (patch)
treeebdcc7c6c9baafb883cfc0d77f457b0e5b804987
parent91767c3848a3c017eb8405ef07283fa0e380e41a (diff)
auto_pairs: move if cursor, extend if selection.
-rw-r--r--helix-core/src/auto_pairs.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/helix-core/src/auto_pairs.rs b/helix-core/src/auto_pairs.rs
index 3ba27105..bbd1cea4 100644
--- a/helix-core/src/auto_pairs.rs
+++ b/helix-core/src/auto_pairs.rs
@@ -69,7 +69,12 @@ fn handle_open(
let pos = range.head;
let next = next_char(doc, pos);
- ranges.push(Range::new(range.anchor, pos + open.len_utf8())); // pos + open
+ let head = pos + open.len_utf8();
+ // if selection, retain anchor, if cursor, move over
+ ranges.push(Range::new(
+ if range.is_empty() { head } else { range.anchor },
+ head,
+ ));
match next {
Some(ch) if !close_before.contains(ch) => {
@@ -98,7 +103,12 @@ fn handle_close(doc: &Rope, selection: &Selection, _open: char, close: char) ->
let pos = range.head;
let next = next_char(doc, pos);
- ranges.push(Range::new(range.anchor, pos + close.len_utf8())); // pos + close
+ let head = pos + close.len_utf8();
+ // if selection, retain anchor, if cursor, move over
+ ranges.push(Range::new(
+ if range.is_empty() { head } else { range.anchor },
+ head,
+ ));
if next == Some(close) {
// return transaction that moves past close