From 641659d5a8dcca0b8a1c36ff6d1c517a91296116 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 22 Aug 2018 11:56:36 +0300 Subject: Smarter extend selection --- crates/libeditor/src/extend_selection.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'crates/libeditor/src') diff --git a/crates/libeditor/src/extend_selection.rs b/crates/libeditor/src/extend_selection.rs index 171e40692..32873f491 100644 --- a/crates/libeditor/src/extend_selection.rs +++ b/crates/libeditor/src/extend_selection.rs @@ -17,18 +17,14 @@ pub(crate) fn extend(root: SyntaxNodeRef, range: TextRange) -> Option return Some(leaf.range()); } let ws = leaves.next()?; -// let ws_suffix = file.text().slice( -// TextRange::from_to(offset, ws.range().end()) -// ); -// if ws.text().contains("\n") && !ws_suffix.contains("\n") { -// if let Some(line_end) = file.text() -// .slice(TextSuffix::from(ws.range().end())) -// .find("\n") -// { -// let range = TextRange::from_len(ws.range().end(), line_end); -// return Some(find_covering_node(file.root(), range).range()); -// } -// } + let ws_text = ws.leaf_text().unwrap(); + let range = TextRange::from_to(offset, ws.range().end()) - ws.range().start(); + let ws_suffix = &ws_text.as_str()[range]; + if ws_text.contains("\n") && !ws_suffix.contains("\n") { + if let Some(node) = ws.next_sibling() { + return Some(node.range()); + } + } return Some(ws.range()); }; let node = find_covering_node(root, range); -- cgit v1.2.3