From 16828d322a13be5b6f9adb680742cdc2570fbf17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Thu, 15 Oct 2020 23:31:37 +0900 Subject: [PATCH] wip --- helix-core/src/indent.rs | 14 ++++++++++---- helix-view/src/commands.rs | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index c834d8e2d..2e1a095ef 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -96,10 +96,8 @@ fn walk(node: Option) -> usize { walk(Some(parent)) + increment } -fn suggested_indent_for_line(state: &State, line_num: usize) -> usize { +fn find_first_non_whitespace_char(state: &State, line_num: usize) -> usize { let line = state.doc.line(line_num); - let current = indent_level_for_line(line); - let mut start = state.doc.line_to_char(line_num); // find first non-whitespace char @@ -110,6 +108,14 @@ fn suggested_indent_for_line(state: &State, line_num: usize) -> usize { } start += 1; } + start +} + +fn suggested_indent_for_line(state: &State, line_num: usize) -> usize { + let line = state.doc.line(line_num); + let current = indent_level_for_line(line); + + let start = find_first_non_whitespace_char(state, line_num); suggested_indent_for_pos(state, start) } @@ -126,7 +132,7 @@ pub fn suggested_indent_for_pos(state: &State, pos: usize) -> usize { indentation } else { - // TODO: case for non-tree sitter grammars + // TODO: heuristics for non-tree sitter grammars 0 } } diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index 542c28ee8..09c6b2fc6 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -349,6 +349,7 @@ pub fn open_below(view: &mut View, _count: usize) { }) .collect(); + // TODO: use same logic as insert_newline for indentation let changes = positions.iter().copied().map(|index| // generate changes (index, index, Some(Tendril::from_char('\n'))));