diff options
author | Bernardo <[email protected]> | 2018-12-08 17:26:19 +0000 |
---|---|---|
committer | Bernardo <[email protected]> | 2018-12-08 17:26:19 +0000 |
commit | c22e9014035c161309e1e13455eb9cdc80c3ee1b (patch) | |
tree | df80d28cdeaeab8b867b12422cbe0e2941df11ca /crates/ra_editor | |
parent | 66f656134f349f943905cfe44f5005263dc635f9 (diff) |
check for empty range when extending in comment
Diffstat (limited to 'crates/ra_editor')
-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] |