@@ -529,19 +529,39 @@ pub fn open_below(cx: &mut Context) {
530 .collect();
530 .collect();
532− // TODO: use same logic as insert_newline for indentation
533− let changes = positions.iter().copied().map(|index|
532+ let changes = positions.iter().copied().map(|index| {
533+ // TODO: share logic with insert_newline for indentation
534+ let indent_level = helix_core::indent::suggested_indent_for_pos(
535+ cx.view.doc.syntax.as_ref(),
539+ let indent = " ".repeat(TAB_WIDTH).repeat(indent_level);
540+ let mut text = String::with_capacity(1 + indent.len());
541+ text.push_str(&indent);
544+ // TODO: ideally we want to run a hook over the transactions to figure out and reindent all
545+ // \n's as a post-processing step?
547+ // - on insert mode enter: we add newline + indent and position cursor at the end
548+ // - on 3o/3O: we insert 3 newlines + indents each and position cursors at ends
534 // generate changes
550 // generate changes
535− (index, index, Some(Tendril::from_char('\n'))));
551+ (index, index, Some(text.into()))
537 // TODO: count actually inserts "n" new lines and starts editing on all of them.
554 // TODO: count actually inserts "n" new lines and starts editing on all of them.
538 // TODO: append "count" newlines and modify cursors to those lines
555 // TODO: append "count" newlines and modify cursors to those lines
540 let selection = Selection::new(
557 let selection = Selection::new(
541− positions
558+ changes
542− .iter()
559+ .clone()
543− .copied()
560+ .map(|(start, end, text): (usize, usize, Option<Tendril>)| {
561+ let len = text.map(|text| text.len()).unwrap() - 1; // minus newline
562+ let pos = start + len;
544− .map(|pos| Range::new(pos, pos))
563+ Range::new(pos, pos)
545 .collect(),
565 .collect(),