diff options
author | Gokul Soumya | 2021-06-17 06:19:02 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-17 09:54:07 +0000 |
commit | 47d2e3aefa5d31c19e7def624057a29c4bc7bc41 (patch) | |
tree | efee74e4ddc43f683e01ce3b27c965cac4e9fb88 /helix-term | |
parent | 20d6b202d5e31f6cd040e73924036f9600112dad (diff) |
Let o, O take counts for multiple cursors
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 59ae0e79..e6ecda06 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -107,6 +107,7 @@ impl<'a> Context<'a> { self.callbacks.push(callback); } + /// Returns 1 if no explicit count was provided #[inline] pub fn count(&self) -> usize { self.count.map_or(1, |v| v.get()) @@ -1511,14 +1512,15 @@ fn open(cx: &mut Context, open: Open) { Open::Above => line, }; - let index = doc.text().line_to_char(line).saturating_sub(1); + // insert newlines after this index for both Above and Below variants + let linend_index = doc.text().line_to_char(line).saturating_sub(1); // TODO: share logic with insert_newline for indentation let indent_level = indent::suggested_indent_for_pos( doc.language_config(), doc.syntax(), text, - index, + linend_index, true, ); let indent = doc.indent_unit().repeat(indent_level); @@ -1527,22 +1529,21 @@ fn open(cx: &mut Context, open: Open) { text.push_str(&indent); let text = text.repeat(count); - // calculate new selection range + // calculate new selection ranges let pos = if line == 0 { 0 // Required since text will have a min len of 1 (\n) } else { - index + offs + text.chars().count() + offs + linend_index + 1 }; - ranges.push(Range::new(pos, pos)); + for i in 0..count { + ranges.push(Range::new(pos + i, pos + i)); + } offs += text.chars().count(); - (index, index, Some(text.into())) + (linend_index, linend_index, Some(text.into())) }); - // TODO: count actually inserts "n" new lines and starts editing on all of them. - // TODO: append "count" newlines and modify cursors to those lines - transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index())); doc.apply(&transaction, view.id); |