diff options
author | Aleksey Kladov <[email protected]> | 2018-08-29 16:35:28 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-29 16:35:28 +0100 |
commit | 7d95d38ecb9b197721e2533ba98afbc2f91610d0 (patch) | |
tree | 51cf2370f95dedc1d7434be1b708e4afa0c7bf7f /crates/libeditor/src/edit.rs | |
parent | 09ea0ca7e5fb5d3e123dc38927b158c798b689ad (diff) |
fix join lines selection
Diffstat (limited to 'crates/libeditor/src/edit.rs')
-rw-r--r-- | crates/libeditor/src/edit.rs | 12 |
1 files changed, 7 insertions, 5 deletions
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 @@ | |||
1 | use {TextRange, TextUnit}; | 1 | use {TextRange, TextUnit}; |
2 | use libsyntax2::AtomEdit; | 2 | use libsyntax2::{ |
3 | AtomEdit, | ||
4 | text_utils::contains_offset_nonstrict, | ||
5 | }; | ||
3 | 6 | ||
4 | #[derive(Debug, Clone)] | 7 | #[derive(Debug, Clone)] |
5 | pub struct Edit { | 8 | pub struct Edit { |
@@ -15,19 +18,15 @@ impl EditBuilder { | |||
15 | pub fn new() -> EditBuilder { | 18 | pub fn new() -> EditBuilder { |
16 | EditBuilder { atoms: Vec::new() } | 19 | EditBuilder { atoms: Vec::new() } |
17 | } | 20 | } |
18 | |||
19 | pub fn replace(&mut self, range: TextRange, replace_with: String) { | 21 | pub fn replace(&mut self, range: TextRange, replace_with: String) { |
20 | self.atoms.push(AtomEdit::replace(range, replace_with)) | 22 | self.atoms.push(AtomEdit::replace(range, replace_with)) |
21 | } | 23 | } |
22 | |||
23 | pub fn delete(&mut self, range: TextRange) { | 24 | pub fn delete(&mut self, range: TextRange) { |
24 | self.atoms.push(AtomEdit::delete(range)) | 25 | self.atoms.push(AtomEdit::delete(range)) |
25 | } | 26 | } |
26 | |||
27 | pub fn insert(&mut self, offset: TextUnit, text: String) { | 27 | pub fn insert(&mut self, offset: TextUnit, text: String) { |
28 | self.atoms.push(AtomEdit::insert(offset, text)) | 28 | self.atoms.push(AtomEdit::insert(offset, text)) |
29 | } | 29 | } |
30 | |||
31 | pub fn finish(self) -> Edit { | 30 | pub fn finish(self) -> Edit { |
32 | let mut atoms = self.atoms; | 31 | let mut atoms = self.atoms; |
33 | atoms.sort_by_key(|a| a.delete.start()); | 32 | atoms.sort_by_key(|a| a.delete.start()); |
@@ -36,6 +35,9 @@ impl EditBuilder { | |||
36 | } | 35 | } |
37 | Edit { atoms } | 36 | Edit { atoms } |
38 | } | 37 | } |
38 | pub fn invalidates_offset(&self, offset: TextUnit) -> bool { | ||
39 | self.atoms.iter().any(|atom| contains_offset_nonstrict(atom.delete, offset)) | ||
40 | } | ||
39 | } | 41 | } |
40 | 42 | ||
41 | impl Edit { | 43 | impl Edit { |