From c22e9014035c161309e1e13455eb9cdc80c3ee1b Mon Sep 17 00:00:00 2001 From: Bernardo Date: Sat, 8 Dec 2018 18:26:19 +0100 Subject: check for empty range when extending in comment --- crates/ra_editor/src/extend_selection.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'crates/ra_editor/src') 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 let from: TextUnit = (start_idx + 1).into(); let to: TextUnit = (cursor_position + end_idx).into(); - Some(TextRange::from_to(from, to) + leaf.range().start()) + let range = TextRange::from_to(from, to); + if range.is_empty() { + None + } else { + Some(range + leaf.range().start()) + } } fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRange { @@ -181,6 +186,20 @@ fn bar(){} "#, &["// 1 + 1", "// fn foo() {\n// 1 + 1\n// }"], ); + + do_check( + r#" +// #[derive(Debug, Clone, Copy, PartialEq, Eq)] +// pub enum Direction { +// <|> Next, +// Prev +// } +"#, + &[ + "// Next,", + "// #[derive(Debug, Clone, Copy, PartialEq, Eq)]\n// pub enum Direction {\n// Next,\n// Prev\n// }", + ], + ); } #[test] -- cgit v1.2.3