From 5d1dae83a12dadcb72d4d3b7010f26250a88c5c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Oct 2018 16:16:51 +0300 Subject: Switch to absolute offsets for extend comment word --- crates/ra_editor/src/extend_selection.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs index e12346cb6..ab03a717e 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs @@ -43,17 +43,17 @@ pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option } fn extend_single_word_in_comment(leaf: SyntaxNodeRef, offset: TextUnit) -> Option { - let text : &str = leaf.leaf_text()?; + let text: &str = leaf.leaf_text()?; let cursor_position: u32 = (offset - leaf.range().start()).into(); let (before, after) = text.split_at(cursor_position as usize); let start_idx = before.rfind(char::is_whitespace)? as u32; let end_idx = after.find(char::is_whitespace)? as u32; - let from : TextUnit = (start_idx + 1).into(); - let to : TextUnit = (cursor_position + end_idx).into(); + let from: TextUnit = (start_idx + 1).into(); + let to: TextUnit = (cursor_position + end_idx).into(); - Some(TextRange::from_to(from, to)) + Some(TextRange::from_to(from, to) + leaf.range().start()) } fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { @@ -219,5 +219,14 @@ fn main() { foo+<|>bar;} r#"// foo bar b<|>az quxx"#, &["baz", "// foo bar baz quxx"] ); + do_check(r#" +impl S { + fn foo() { + // hel<|>lo world + } +} + "#, + &["hello", "// hello world"] + ); } } -- cgit v1.2.3