Convert common edit strings to Arc<str> and simplify duplicate line
This commit is contained in:
parent
2c2ca1bfbd
commit
2eb1c107ce
2 changed files with 26 additions and 8 deletions
|
@ -3027,7 +3027,13 @@ impl Editor {
|
|||
|
||||
self.transact(cx, |this, cx| {
|
||||
this.buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit(deletion_ranges.into_iter().map(|range| (range, "")), cx);
|
||||
let empty_str: Arc<str> = "".into();
|
||||
buffer.edit(
|
||||
deletion_ranges
|
||||
.into_iter()
|
||||
.map(|range| (range, empty_str.clone())),
|
||||
cx,
|
||||
);
|
||||
});
|
||||
this.update_selections(
|
||||
this.local_selections::<usize>(cx),
|
||||
|
@ -3089,7 +3095,13 @@ impl Editor {
|
|||
|
||||
self.transact(cx, |this, cx| {
|
||||
let buffer = this.buffer.update(cx, |buffer, cx| {
|
||||
buffer.edit(edit_ranges.into_iter().map(|range| (range, "")), cx);
|
||||
let empty_str: Arc<str> = "".into();
|
||||
buffer.edit(
|
||||
edit_ranges
|
||||
.into_iter()
|
||||
.map(|range| (range, empty_str.clone())),
|
||||
cx,
|
||||
);
|
||||
buffer.snapshot(cx)
|
||||
});
|
||||
let new_selections = new_cursors
|
||||
|
@ -3137,14 +3149,12 @@ impl Editor {
|
|||
.text_for_range(start..end)
|
||||
.chain(Some("\n"))
|
||||
.collect::<String>();
|
||||
edits.push((start, text, rows.len() as u32));
|
||||
edits.push((start..start, text));
|
||||
}
|
||||
|
||||
self.transact(cx, |this, cx| {
|
||||
this.buffer.update(cx, |buffer, cx| {
|
||||
for (point, text, _) in edits.into_iter().rev() {
|
||||
buffer.edit([(point..point, text)], cx);
|
||||
}
|
||||
buffer.edit(edits, cx);
|
||||
});
|
||||
|
||||
this.request_autoscroll(Autoscroll::Fit, cx);
|
||||
|
@ -4259,7 +4269,14 @@ impl Editor {
|
|||
|
||||
if !edit_ranges.is_empty() {
|
||||
if all_selection_lines_are_comments {
|
||||
buffer.edit(edit_ranges.iter().cloned().map(|range| (range, "")), cx);
|
||||
let empty_str: Arc<str> = "".into();
|
||||
buffer.edit(
|
||||
edit_ranges
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|range| (range, empty_str.clone())),
|
||||
cx,
|
||||
);
|
||||
} else {
|
||||
let min_column =
|
||||
edit_ranges.iter().map(|r| r.start.column).min().unwrap();
|
||||
|
|
|
@ -377,6 +377,7 @@ impl MultiBuffer {
|
|||
let mut edits = edits.into_iter().peekable();
|
||||
let mut insertions = Vec::new();
|
||||
let mut deletions = Vec::new();
|
||||
let empty_str: Arc<str> = "".into();
|
||||
while let Some((mut range, mut new_text, mut is_insertion)) = edits.next() {
|
||||
while let Some((next_range, next_new_text, next_is_insertion)) =
|
||||
edits.peek()
|
||||
|
@ -399,7 +400,7 @@ impl MultiBuffer {
|
|||
} else if !range.is_empty() {
|
||||
deletions.push((
|
||||
buffer.anchor_before(range.start)..buffer.anchor_before(range.end),
|
||||
"",
|
||||
empty_str.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue