aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor')
-rw-r--r--crates/ra_editor/src/extend_selection.rs26
1 files changed, 11 insertions, 15 deletions
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs
index 5946824d8..a6cb1acf5 100644
--- a/crates/ra_editor/src/extend_selection.rs
+++ b/crates/ra_editor/src/extend_selection.rs
@@ -20,7 +20,7 @@ pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange>
20 LeafAtOffset::None => return None, 20 LeafAtOffset::None => return None,
21 LeafAtOffset::Single(l) => { 21 LeafAtOffset::Single(l) => {
22 if l.kind() == COMMENT { 22 if l.kind() == COMMENT {
23 extend_single_word_in_comment(l, range).unwrap_or_else(||l.range()) 23 extend_single_word_in_comment(l, offset).unwrap_or_else(||l.range())
24 } else { 24 } else {
25 l.range() 25 l.range()
26 } 26 }
@@ -42,22 +42,18 @@ pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange>
42 } 42 }
43} 43}
44 44
45fn extend_single_word_in_comment(leaf: SyntaxNodeRef, range: TextRange) -> Option<TextRange> { 45fn extend_single_word_in_comment(leaf: SyntaxNodeRef, offset: TextUnit) -> Option<TextRange> {
46 let text : &str = leaf.leaf_text().unwrap(); 46 let text : &str = leaf.leaf_text()?;
47 let cursor_position: u32 = (range.start() - leaf.range().start()).into(); 47 let cursor_position: u32 = (offset - leaf.range().start()).into();
48 48
49 let (before, after) = text.split_at(cursor_position as usize); 49 let (before, after) = text.split_at(cursor_position as usize);
50 let start_idx = before.rfind(char::is_whitespace); 50 let start_idx = before.rfind(char::is_whitespace)?;
51 let end_idx = after.find(char::is_whitespace); 51 let end_idx = after.find(char::is_whitespace)?;
52 52
53 match (start_idx, end_idx) { 53 let from : TextUnit = (start_idx as u32 + 1).into();
54 (Some(start), Some(end)) => { 54 let to : TextUnit = (cursor_position + (end_idx as u32)).into();
55 let from : TextUnit = (start as u32 + 1).into(); 55
56 let to : TextUnit = (cursor_position + (end as u32)).into(); 56 Some(TextRange::from_to(from, to))
57 Some(TextRange::from_to(from, to))
58 },
59 (_, _) => None
60 }
61} 57}
62 58
63fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { 59fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange {