From 7d95d38ecb9b197721e2533ba98afbc2f91610d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 29 Aug 2018 18:35:28 +0300 Subject: fix join lines selection --- crates/libeditor/src/edit.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'crates/libeditor/src/edit.rs') diff --git a/crates/libeditor/src/edit.rs b/crates/libeditor/src/edit.rs index dcf1ee81e..09cf2bd00 100644 --- a/crates/libeditor/src/edit.rs +++ b/crates/libeditor/src/edit.rs @@ -1,5 +1,8 @@ use {TextRange, TextUnit}; -use libsyntax2::AtomEdit; +use libsyntax2::{ + AtomEdit, + text_utils::contains_offset_nonstrict, +}; #[derive(Debug, Clone)] pub struct Edit { @@ -15,19 +18,15 @@ impl EditBuilder { pub fn new() -> EditBuilder { EditBuilder { atoms: Vec::new() } } - pub fn replace(&mut self, range: TextRange, replace_with: String) { self.atoms.push(AtomEdit::replace(range, replace_with)) } - pub fn delete(&mut self, range: TextRange) { self.atoms.push(AtomEdit::delete(range)) } - pub fn insert(&mut self, offset: TextUnit, text: String) { self.atoms.push(AtomEdit::insert(offset, text)) } - pub fn finish(self) -> Edit { let mut atoms = self.atoms; atoms.sort_by_key(|a| a.delete.start()); @@ -36,6 +35,9 @@ impl EditBuilder { } Edit { atoms } } + pub fn invalidates_offset(&self, offset: TextUnit) -> bool { + self.atoms.iter().any(|atom| contains_offset_nonstrict(atom.delete, offset)) + } } impl Edit { -- cgit v1.2.3