on master help sign in
wip
commit16828d322a13be5b6f9adb680742cdc2570fbf17 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 15 Oct 2020, 23:31 (6 years ago) parent6e658aa
2 files changed+11−4
helix-core/src/indent.rs+10−4 helix-view/src/commands.rs+1
helix-core/src/indent.rs+10−4
@@ -96,10 +96,8 @@ fn walk(node: Option<Node>) -> usize {
9696 walk(Some(parent)) + increment
9797}
9898
99−fn suggested_indent_for_line(state: &State, line_num: usize) -> usize {
99+fn find_first_non_whitespace_char(state: &State, line_num: usize) -> usize {
100100 let line = state.doc.line(line_num);
101− let current = indent_level_for_line(line);
102−
103101 let mut start = state.doc.line_to_char(line_num);
104102
105103 // find first non-whitespace char
@@ -110,6 +108,14 @@ fn suggested_indent_for_line(state: &State, line_num: usize) -> usize {
110108 }
111109 start += 1;
112110 }
111+ start
112+}
113+
114+fn suggested_indent_for_line(state: &State, line_num: usize) -> usize {
115+ let line = state.doc.line(line_num);
116+ let current = indent_level_for_line(line);
117+
118+ let start = find_first_non_whitespace_char(state, line_num);
113119
114120 suggested_indent_for_pos(state, start)
115121}
@@ -126,7 +132,7 @@ pub fn suggested_indent_for_pos(state: &State, pos: usize) -> usize {
126132
127133 indentation
128134 } else {
129− // TODO: case for non-tree sitter grammars
135+ // TODO: heuristics for non-tree sitter grammars
130136 0
131137 }
132138}
helix-view/src/commands.rs+1
@@ -349,6 +349,7 @@ pub fn open_below(view: &mut View, _count: usize) {
349349 })
350350 .collect();
351351
352+ // TODO: use same logic as insert_newline for indentation
352353 let changes = positions.iter().copied().map(|index|
353354 // generate changes
354355 (index, index, Some(Tendril::from_char('\n'))));