Skip to content

Commit 4b433d2

Browse files
bors[bot]vemoo
andcommitted
Merge #272
272: use \b as word boundary when expanding single word in comments r=matklad a=vemoo as discused in #266 Co-authored-by: Bernardo <[email protected]>
2 parents 3725276 + a062d84 commit 4b433d2

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

crates/ra_editor/src/extend_selection.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ fn extend_single_word_in_comment(leaf: SyntaxNodeRef, offset: TextUnit) -> Optio
4848
let cursor_position: u32 = (offset - leaf.range().start()).into();
4949

5050
let (before, after) = text.split_at(cursor_position as usize);
51-
let start_idx = before.rfind(char::is_whitespace).unwrap_or(0) as u32;
52-
let end_idx = after.find(char::is_whitespace).unwrap_or(after.len()) as u32;
51+
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;
5358

5459
let from: TextUnit = (start_idx + 1).into();
5560
let to: TextUnit = (cursor_position + end_idx).into();
@@ -200,6 +205,29 @@ fn bar(){}
200205
"// #[derive(Debug, Clone, Copy, PartialEq, Eq)]\n// pub enum Direction {\n// Next,\n// Prev\n// }",
201206
],
202207
);
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+
);
203231
}
204232

205233
#[test]

0 commit comments

Comments
 (0)