@@ -107,6 +107,7 @@ impl<'a> Context<'a> {
107 self.callbacks.push(callback);
107 self.callbacks.push(callback);
110+ /// Returns 1 if no explicit count was provided
110 #[inline]
111 #[inline]
111 pub fn count(&self) -> usize {
112 pub fn count(&self) -> usize {
112 self.count.map_or(1, |v| v.get())
113 self.count.map_or(1, |v| v.get())
@@ -1511,14 +1512,15 @@ fn open(cx: &mut Context, open: Open) {
1511 Open::Above => line,
1512 Open::Above => line,
1515+ // insert newlines after this index for both Above and Below variants
1514− let index = doc.text().line_to_char(line).saturating_sub(1);
1516+ let linend_index = doc.text().line_to_char(line).saturating_sub(1);
1516 // TODO: share logic with insert_newline for indentation
1518 // TODO: share logic with insert_newline for indentation
1517 let indent_level = indent::suggested_indent_for_pos(
1519 let indent_level = indent::suggested_indent_for_pos(
1518 doc.language_config(),
1520 doc.language_config(),
1519 doc.syntax(),
1521 doc.syntax(),
1521− index,
1523+ linend_index,
1524 let indent = doc.indent_unit().repeat(indent_level);
1526 let indent = doc.indent_unit().repeat(indent_level);
@@ -1527,22 +1529,21 @@ fn open(cx: &mut Context, open: Open) {
1527 text.push_str(&indent);
1529 text.push_str(&indent);
1528 let text = text.repeat(count);
1530 let text = text.repeat(count);
1530− // calculate new selection range
1532+ // calculate new selection ranges
1531 let pos = if line == 0 {
1533 let pos = if line == 0 {
1532 0 // Required since text will have a min len of 1 (\n)
1534 0 // Required since text will have a min len of 1 (\n)
1533 } else {
1535 } else {
1534− index + offs + text.chars().count()
1536+ offs + linend_index + 1
1538+ for i in 0..count {
1536− ranges.push(Range::new(pos, pos));
1539+ ranges.push(Range::new(pos + i, pos + i));
1538 offs += text.chars().count();
1542 offs += text.chars().count();
1540− (index, index, Some(text.into()))
1544+ (linend_index, linend_index, Some(text.into()))
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
1546 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
1547 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));
1548 doc.apply(&transaction, view.id);
1549 doc.apply(&transaction, view.id);