open_below is now indentation-aware.

imgbot
Blaž Hrastnik 4 years ago
parent 8b95c3353b
commit b2800489de

@ -529,19 +529,39 @@ pub fn open_below(cx: &mut Context) {
}) })
.collect(); .collect();
// TODO: use same logic as insert_newline for indentation let changes = positions.iter().copied().map(|index| {
let changes = positions.iter().copied().map(|index| // TODO: share logic with insert_newline for indentation
let indent_level = helix_core::indent::suggested_indent_for_pos(
cx.view.doc.syntax.as_ref(),
&cx.view.doc.state,
index,
);
let indent = " ".repeat(TAB_WIDTH).repeat(indent_level);
let mut text = String::with_capacity(1 + indent.len());
text.push_str(&indent);
text.push('\n');
// TODO: ideally we want to run a hook over the transactions to figure out and reindent all
// \n's as a post-processing step?
// behaviors:
// - on insert mode enter: we add newline + indent and position cursor at the end
// - on 3o/3O: we insert 3 newlines + indents each and position cursors at ends
// generate changes // generate changes
(index, index, Some(Tendril::from_char('\n')))); (index, index, Some(text.into()))
});
// TODO: count actually inserts "n" new lines and starts editing on all of them. // TODO: count actually inserts "n" new lines and starts editing on all of them.
// TODO: append "count" newlines and modify cursors to those lines // TODO: append "count" newlines and modify cursors to those lines
let selection = Selection::new( let selection = Selection::new(
positions changes
.iter() .clone()
.copied() .map(|(start, end, text): (usize, usize, Option<Tendril>)| {
.map(|pos| Range::new(pos, pos)) let len = text.map(|text| text.len()).unwrap() - 1; // minus newline
let pos = start + len;
Range::new(pos, pos)
})
.collect(), .collect(),
0, 0,
); );

Loading…
Cancel
Save