mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
find next whitespace or begining or end
This commit is contained in:
parent
97b07ac393
commit
6fb267f5da
1 changed files with 3 additions and 3 deletions
|
@ -48,8 +48,8 @@ fn extend_single_word_in_comment(leaf: SyntaxNodeRef, offset: TextUnit) -> Optio
|
||||||
let cursor_position: u32 = (offset - leaf.range().start()).into();
|
let cursor_position: u32 = (offset - leaf.range().start()).into();
|
||||||
|
|
||||||
let (before, after) = text.split_at(cursor_position as usize);
|
let (before, after) = text.split_at(cursor_position as usize);
|
||||||
let start_idx = before.rfind(char::is_whitespace)? as u32;
|
let start_idx = before.rfind(char::is_whitespace).unwrap_or(0) as u32;
|
||||||
let end_idx = after.find(char::is_whitespace)? as u32;
|
let end_idx = after.find(char::is_whitespace).unwrap_or(after.len()) as u32;
|
||||||
|
|
||||||
let from: TextUnit = (start_idx + 1).into();
|
let from: TextUnit = (start_idx + 1).into();
|
||||||
let to: TextUnit = (cursor_position + end_idx).into();
|
let to: TextUnit = (cursor_position + end_idx).into();
|
||||||
|
@ -184,7 +184,7 @@ fn bar(){}
|
||||||
|
|
||||||
// fn foo(){}
|
// fn foo(){}
|
||||||
"#,
|
"#,
|
||||||
&["// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"],
|
&["1", "// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"],
|
||||||
);
|
);
|
||||||
|
|
||||||
do_check(
|
do_check(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue