diff options
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r-- | crates/ra_editor/src/extend_selection.rs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs index a2aa02149..4665a336a 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs | |||
@@ -48,8 +48,13 @@ 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).unwrap_or(0) as u32; | 51 | |
52 | let end_idx = after.find(char::is_whitespace).unwrap_or(after.len()) as u32; | 52 | fn non_word_char(c: char) -> bool { |
53 | !(c.is_alphanumeric() || c == '_') | ||
54 | } | ||
55 | |||
56 | let start_idx = before.rfind(non_word_char)? as u32; | ||
57 | let end_idx = after.find(non_word_char).unwrap_or(after.len()) as u32; | ||
53 | 58 | ||
54 | let from: TextUnit = (start_idx + 1).into(); | 59 | let from: TextUnit = (start_idx + 1).into(); |
55 | let to: TextUnit = (cursor_position + end_idx).into(); | 60 | let to: TextUnit = (cursor_position + end_idx).into(); |
@@ -200,6 +205,29 @@ fn bar(){} | |||
200 | "// #[derive(Debug, Clone, Copy, PartialEq, Eq)]\n// pub enum Direction {\n// Next,\n// Prev\n// }", | 205 | "// #[derive(Debug, Clone, Copy, PartialEq, Eq)]\n// pub enum Direction {\n// Next,\n// Prev\n// }", |
201 | ], | 206 | ], |
202 | ); | 207 | ); |
208 | |||
209 | do_check( | ||
210 | r#" | ||
211 | /* | ||
212 | foo | ||
213 | _bar1<|>*/ | ||
214 | "#, | ||
215 | &["_bar1", "/*\nfoo\n_bar1*/"], | ||
216 | ); | ||
217 | |||
218 | do_check( | ||
219 | r#" | ||
220 | //!<|>foo_2 bar | ||
221 | "#, | ||
222 | &["foo_2", "//!foo_2 bar"], | ||
223 | ); | ||
224 | |||
225 | do_check( | ||
226 | r#" | ||
227 | /<|>/foo bar | ||
228 | "#, | ||
229 | &["//foo bar"], | ||
230 | ); | ||
203 | } | 231 | } |
204 | 232 | ||
205 | #[test] | 233 | #[test] |