aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-05-15 01:26:41 +0000
committerBlaž Hrastnik2021-05-15 01:50:36 +0000
commit0e5b42164628e5d25044cb5fd9592f7222701d6f (patch)
tree8cb1b7600d14dd28a4b13dfe9d74f594006d9cef /helix-term/src
parent4a9d1163e04ba0fc29f8532afd35381b7df55e48 (diff)
When calculating a new selection, we need to take newly inserted text into account.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 104df72f..5520c5af 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1644,6 +1644,9 @@ pub mod insert {
let selection = doc.selection(view.id);
let mut ranges = SmallVec::with_capacity(selection.len());
+ // TODO: this is annoying, but we need to do it to properly calculate pos after edits
+ let mut offs = 0;
+
let mut transaction = Transaction::change_by_selection(contents, selection, |range| {
let pos = range.head;
@@ -1667,10 +1670,14 @@ pub mod insert {
text.push('\n');
text.push_str(&indent);
- let head = pos + text.len();
+ let head = pos + offs + text.len();
ranges.push(Range::new(
- if range.is_empty() { head } else { range.anchor },
+ if range.is_empty() {
+ head
+ } else {
+ range.anchor + offs
+ },
head,
));
@@ -1680,11 +1687,11 @@ pub mod insert {
let indent = doc.indent_unit().repeat(indent_level.saturating_sub(1));
text.push('\n');
text.push_str(&indent);
-
- (pos, pos, Some(text.into()))
- } else {
- (pos, pos, Some(text.into()))
}
+
+ offs += text.len();
+
+ (pos, pos, Some(text.into()))
});
transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));