aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorBernardo <[email protected]>2018-12-09 14:50:56 +0000
committerBernardo <[email protected]>2018-12-09 14:50:56 +0000
commita062d844c21788c276c38760029a849737fed9b3 (patch)
tree65eda8ea06c9ab8228b7f98c66e57a33cb5e533c /crates
parent3725276554fe63fdd9b63a10b86e794b3eb73158 (diff)
use \b as word boundary
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_editor/src/extend_selection.rs32
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/*
212foo
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]