diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-08 17:43:15 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-08 17:43:15 +0000 |
commit | 5ad7547ce2f469905992acff5f95e55d54eda714 (patch) | |
tree | 5e411617084fb8ba199209d1dd7cb90e05a99a33 /crates | |
parent | e096867ada7c298dd9dc533880424c4d9b62cd34 (diff) | |
parent | c22e9014035c161309e1e13455eb9cdc80c3ee1b (diff) |
Merge #264
264: check for empty range when extending in comment r=matklad a=vemoo
fix for #140
Co-authored-by: Bernardo <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_editor/src/extend_selection.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs index 8f11d5364..b4227716d 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs | |||
@@ -54,7 +54,12 @@ fn extend_single_word_in_comment(leaf: SyntaxNodeRef, offset: TextUnit) -> Optio | |||
54 | let from: TextUnit = (start_idx + 1).into(); | 54 | let from: TextUnit = (start_idx + 1).into(); |
55 | let to: TextUnit = (cursor_position + end_idx).into(); | 55 | let to: TextUnit = (cursor_position + end_idx).into(); |
56 | 56 | ||
57 | Some(TextRange::from_to(from, to) + leaf.range().start()) | 57 | let range = TextRange::from_to(from, to); |
58 | if range.is_empty() { | ||
59 | None | ||
60 | } else { | ||
61 | Some(range + leaf.range().start()) | ||
62 | } | ||
58 | } | 63 | } |
59 | 64 | ||
60 | fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { | 65 | fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { |
@@ -181,6 +186,20 @@ fn bar(){} | |||
181 | "#, | 186 | "#, |
182 | &["// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"], | 187 | &["// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"], |
183 | ); | 188 | ); |
189 | |||
190 | do_check( | ||
191 | r#" | ||
192 | // #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
193 | // pub enum Direction { | ||
194 | // <|> Next, | ||
195 | // Prev | ||
196 | // } | ||
197 | "#, | ||
198 | &[ | ||
199 | "// Next,", | ||
200 | "// #[derive(Debug, Clone, Copy, PartialEq, Eq)]\n// pub enum Direction {\n// Next,\n// Prev\n// }", | ||
201 | ], | ||
202 | ); | ||
184 | } | 203 | } |
185 | 204 | ||
186 | #[test] | 205 | #[test] |