aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src/extend_selection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor/src/extend_selection.rs')
-rw-r--r--crates/ra_editor/src/extend_selection.rs27
1 files changed, 23 insertions, 4 deletions
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs
index 8f11d5364..a2aa02149 100644
--- a/crates/ra_editor/src/extend_selection.rs
+++ b/crates/ra_editor/src/extend_selection.rs
@@ -48,13 +48,18 @@ 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();
56 56
57 Some(TextRange::from_to(from, to) + leaf.range().start()) 57 let range = TextRange::from_to(from, to);
58 if range.is_empty() {
59 None
60 } else {
61 Some(range + leaf.range().start())
62 }
58} 63}
59 64
60fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { 65fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange {
@@ -179,7 +184,21 @@ fn bar(){}
179 184
180// fn foo(){} 185// fn foo(){}
181 "#, 186 "#,
182 &["// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"], 187 &["1", "// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"],
188 );
189
190 do_check(
191 r#"
192// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
193// pub enum Direction {
194// <|> Next,
195// Prev
196// }
197"#,
198 &[
199 "// Next,",
200 "// #[derive(Debug, Clone, Copy, PartialEq, Eq)]\n// pub enum Direction {\n// Next,\n// Prev\n// }",
201 ],
183 ); 202 );
184 } 203 }
185 204