diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-08 20:28:35 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-08 20:28:35 +0000 |
commit | c011fb70563d9eddb1e62436f78c206f3be0d00e (patch) | |
tree | 3fb667422899d19edd914fa9e65d586ace62b0aa | |
parent | 97b07ac393caebaa76099f97672ad4399c0ceda6 (diff) | |
parent | 6fb267f5da9acb78f89a6ab0cedf7d1f904b16c3 (diff) |
Merge #266
266: handle expanding of words in comments at the beginning or end of line r=matklad a=vemoo
After fixing #140 i realized that the logic to determine word boundaries was not correct. It would only consider a word something surrounded by whitespaces in the line, but not newlines before and after the line. This means that one of the tests has changed, but i think that's what was intended.
Co-authored-by: Bernardo <[email protected]>
-rw-r--r-- | crates/ra_editor/src/extend_selection.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs index b4227716d..a2aa02149 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs | |||
@@ -48,8 +48,8 @@ fn extend_single_word_in_comment(leaf: SyntaxNodeRef, offset: TextUnit) -> Optio | |||
48 | let cursor_position: u32 = (offset - leaf.range().start()).into(); | 48 | let cursor_position: u32 = (offset - leaf.range().start()).into(); |
49 | 49 | ||
50 | let (before, after) = text.split_at(cursor_position as usize); | 50 | let (before, after) = text.split_at(cursor_position as usize); |
51 | let start_idx = before.rfind(char::is_whitespace)? as u32; | 51 | let start_idx = before.rfind(char::is_whitespace).unwrap_or(0) as u32; |
52 | let end_idx = after.find(char::is_whitespace)? as u32; | 52 | let end_idx = after.find(char::is_whitespace).unwrap_or(after.len()) as u32; |
53 | 53 | ||
54 | let from: TextUnit = (start_idx + 1).into(); | 54 | let from: TextUnit = (start_idx + 1).into(); |
55 | let to: TextUnit = (cursor_position + end_idx).into(); | 55 | let to: TextUnit = (cursor_position + end_idx).into(); |
@@ -184,7 +184,7 @@ fn bar(){} | |||
184 | 184 | ||
185 | // fn foo(){} | 185 | // fn foo(){} |
186 | "#, | 186 | "#, |
187 | &["// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"], | 187 | &["1", "// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"], |
188 | ); | 188 | ); |
189 | 189 | ||
190 | do_check( | 190 | do_check( |