on master help sign in
Let o, O take counts for multiple cursors
commit47d2e3aefa5d31c19e7def624057a29c4bc7bc41 authorGokul Soumya <gokulps15@gmail.com> dateThu 17 Jun 2021, 11:49 (5 years ago) parent20d6b20
1 file changed+10−9
helix-term/src/commands.rs+10−9
helix-term/src/commands.rs+10−9
@@ -107,6 +107,7 @@ impl<'a> Context<'a> {
107107 self.callbacks.push(callback);
108108 }
109109
110+ /// Returns 1 if no explicit count was provided
110111 #[inline]
111112 pub fn count(&self) -> usize {
112113 self.count.map_or(1, |v| v.get())
@@ -1511,14 +1512,15 @@ fn open(cx: &mut Context, open: Open) {
15111512 Open::Above => line,
15121513 };
15131514
1514− let index = doc.text().line_to_char(line).saturating_sub(1);
1515+ // insert newlines after this index for both Above and Below variants
1516+ let linend_index = doc.text().line_to_char(line).saturating_sub(1);
15151517
15161518 // TODO: share logic with insert_newline for indentation
15171519 let indent_level = indent::suggested_indent_for_pos(
15181520 doc.language_config(),
15191521 doc.syntax(),
15201522 text,
1521− index,
1523+ linend_index,
15221524 true,
15231525 );
15241526 let indent = doc.indent_unit().repeat(indent_level);
@@ -1527,22 +1529,21 @@ fn open(cx: &mut Context, open: Open) {
15271529 text.push_str(&indent);
15281530 let text = text.repeat(count);
15291531
1530− // calculate new selection range
1532+ // calculate new selection ranges
15311533 let pos = if line == 0 {
15321534 0 // Required since text will have a min len of 1 (\n)
15331535 } else {
1534− index + offs + text.chars().count()
1536+ offs + linend_index + 1
15351537 };
1536− ranges.push(Range::new(pos, pos));
1538+ for i in 0..count {
1539+ ranges.push(Range::new(pos + i, pos + i));
1540+ }
15371541
15381542 offs += text.chars().count();
15391543
1540− (index, index, Some(text.into()))
1544+ (linend_index, linend_index, Some(text.into()))
15411545 });
15421546
1543− // TODO: count actually inserts "n" new lines and starts editing on all of them.
1544− // TODO: append "count" newlines and modify cursors to those lines
1545−
15461547 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
15471548
15481549 doc.apply(&transaction, view.id);