diff options
author | Wojciech Kępka | 2021-06-08 07:11:45 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-08 08:22:37 +0000 |
commit | c978d811d96d03acf04ddbe5af66fff57c17e287 (patch) | |
tree | d7e9c0deb5ee6addf25381ab977ca2714d06cc31 /helix-core | |
parent | 48df05b16dba362366b63284c2e551c51995fb66 (diff) |
Cleanup find_first_non_whitespace_char funcs
Diffstat (limited to 'helix-core')
-rw-r--r-- | helix-core/src/comment.rs | 4 | ||||
-rw-r--r-- | helix-core/src/indent.rs | 13 | ||||
-rw-r--r-- | helix-core/src/lib.rs | 17 |
3 files changed, 11 insertions, 23 deletions
diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs index fd9d9058..dff99bab 100644 --- a/helix-core/src/comment.rs +++ b/helix-core/src/comment.rs @@ -1,5 +1,5 @@ use crate::{ - find_first_non_whitespace_char2, Change, Rope, RopeSlice, Selection, Tendril, Transaction, + find_first_non_whitespace_char, Change, Rope, RopeSlice, Selection, Tendril, Transaction, }; use core::ops::Range; use std::borrow::Cow; @@ -14,7 +14,7 @@ fn find_line_comment( let mut min = usize::MAX; // minimum col for find_first_non_whitespace_char for line in lines { let line_slice = text.line(line); - if let Some(pos) = find_first_non_whitespace_char2(line_slice) { + if let Some(pos) = find_first_non_whitespace_char(line_slice) { let len = line_slice.len_chars(); if pos < min { diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index 7ab810fd..9032d660 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -105,11 +105,14 @@ fn suggested_indent_for_line( line_num: usize, tab_width: usize, ) -> usize { - let line = text.line(line_num); - let current = indent_level_for_line(line, tab_width); - - if let Some(start) = find_first_non_whitespace_char(text, line_num) { - return suggested_indent_for_pos(Some(language_config), syntax, text, start, false); + if let Some(start) = find_first_non_whitespace_char(text.line(line_num)) { + return suggested_indent_for_pos( + Some(language_config), + syntax, + text, + start + text.line_to_char(line_num), + false, + ); }; // if the line is blank, indent should be zero diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index da48ba7e..f5e7de52 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -18,24 +18,9 @@ pub mod syntax; mod transaction; pub mod words; -pub fn find_first_non_whitespace_char2(line: RopeSlice) -> Option<usize> { +pub fn find_first_non_whitespace_char(line: RopeSlice) -> Option<usize> { line.chars().position(|ch| !ch.is_whitespace()) } -pub(crate) fn find_first_non_whitespace_char(text: RopeSlice, line_num: usize) -> Option<usize> { - let line = text.line(line_num); - let mut start = text.line_to_char(line_num); - - // find first non-whitespace char - for ch in line.chars() { - // TODO: could use memchr with chunks? - if ch != ' ' && ch != '\t' && ch != '\n' { - return Some(start); - } - start += 1; - } - - None -} pub fn find_root(root: Option<&str>) -> Option<std::path::PathBuf> { let current_dir = std::env::current_dir().expect("unable to determine current directory"); |