mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Move edited_ranges_for_transaction from BufferSnapshot to Buffer
Co-authored-by: Antonio Scandurra <antonio@zed.dev>
This commit is contained in:
parent
7b009c8bbe
commit
65fd943509
@ -2480,14 +2480,17 @@ impl Editor {
|
||||
});
|
||||
if let Some((_, excerpted_buffer, excerpt_range)) = excerpt {
|
||||
if excerpted_buffer == *buffer {
|
||||
let snapshot = buffer.read_with(&cx, |buffer, _| buffer.snapshot());
|
||||
let excerpt_range = excerpt_range.to_offset(&snapshot);
|
||||
if snapshot
|
||||
.edited_ranges_for_transaction(transaction)
|
||||
.all(|range| {
|
||||
excerpt_range.start <= range.start && excerpt_range.end >= range.end
|
||||
})
|
||||
{
|
||||
let all_edits_within_excerpt = buffer.read_with(&cx, |buffer, _| {
|
||||
let excerpt_range = excerpt_range.to_offset(buffer);
|
||||
buffer
|
||||
.edited_ranges_for_transaction(transaction)
|
||||
.all(|range| {
|
||||
excerpt_range.start <= range.start
|
||||
&& excerpt_range.end >= range.end
|
||||
})
|
||||
});
|
||||
|
||||
if all_edits_within_excerpt {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@ -2500,12 +2503,12 @@ impl Editor {
|
||||
let mut ranges_to_highlight = Vec::new();
|
||||
let excerpt_buffer = cx.add_model(|cx| {
|
||||
let mut multibuffer = MultiBuffer::new(replica_id).with_title(title);
|
||||
for (buffer, transaction) in &entries {
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
for (buffer_handle, transaction) in &entries {
|
||||
let buffer = buffer_handle.read(cx);
|
||||
ranges_to_highlight.extend(
|
||||
multibuffer.push_excerpts_with_context_lines(
|
||||
buffer.clone(),
|
||||
snapshot
|
||||
buffer_handle.clone(),
|
||||
buffer
|
||||
.edited_ranges_for_transaction::<usize>(transaction)
|
||||
.collect(),
|
||||
1,
|
||||
|
@ -1322,6 +1322,42 @@ impl Buffer {
|
||||
self.history.finalize_last_transaction();
|
||||
}
|
||||
|
||||
pub fn edited_ranges_for_transaction<'a, D>(
|
||||
&'a self,
|
||||
transaction: &'a Transaction,
|
||||
) -> impl 'a + Iterator<Item = Range<D>>
|
||||
where
|
||||
D: TextDimension,
|
||||
{
|
||||
let mut cursor = self.fragments.cursor::<(VersionedFullOffset, usize)>();
|
||||
let mut rope_cursor = self.visible_text.cursor(0);
|
||||
let cx = Some(transaction.end.clone());
|
||||
let mut position = D::default();
|
||||
transaction.ranges.iter().map(move |range| {
|
||||
cursor.seek_forward(&VersionedFullOffset::Offset(range.start), Bias::Right, &cx);
|
||||
let mut start_offset = cursor.start().1;
|
||||
if cursor
|
||||
.item()
|
||||
.map_or(false, |fragment| fragment.is_visible(&self.undo_map))
|
||||
{
|
||||
start_offset += range.start - cursor.start().0.full_offset()
|
||||
}
|
||||
position.add_assign(&rope_cursor.summary(start_offset));
|
||||
let start = position.clone();
|
||||
|
||||
cursor.seek_forward(&VersionedFullOffset::Offset(range.end), Bias::Left, &cx);
|
||||
let mut end_offset = cursor.start().1;
|
||||
if cursor
|
||||
.item()
|
||||
.map_or(false, |fragment| fragment.is_visible(&self.undo_map))
|
||||
{
|
||||
end_offset += range.end - cursor.start().0.full_offset();
|
||||
}
|
||||
position.add_assign(&rope_cursor.summary(end_offset));
|
||||
start..position.clone()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn subscribe(&mut self) -> Subscription {
|
||||
self.subscriptions.subscribe()
|
||||
}
|
||||
@ -1878,42 +1914,6 @@ impl BufferSnapshot {
|
||||
self.edits_since_in_range(since, Anchor::MIN..Anchor::MAX)
|
||||
}
|
||||
|
||||
pub fn edited_ranges_for_transaction<'a, D>(
|
||||
&'a self,
|
||||
transaction: &'a Transaction,
|
||||
) -> impl 'a + Iterator<Item = Range<D>>
|
||||
where
|
||||
D: TextDimension,
|
||||
{
|
||||
let mut cursor = self.fragments.cursor::<(VersionedFullOffset, usize)>();
|
||||
let mut rope_cursor = self.visible_text.cursor(0);
|
||||
let cx = Some(transaction.end.clone());
|
||||
let mut position = D::default();
|
||||
transaction.ranges.iter().map(move |range| {
|
||||
cursor.seek_forward(&VersionedFullOffset::Offset(range.start), Bias::Right, &cx);
|
||||
let mut start_offset = cursor.start().1;
|
||||
if cursor
|
||||
.item()
|
||||
.map_or(false, |fragment| fragment.is_visible(&self.undo_map))
|
||||
{
|
||||
start_offset += range.start - cursor.start().0.full_offset()
|
||||
}
|
||||
position.add_assign(&rope_cursor.summary(start_offset));
|
||||
let start = position.clone();
|
||||
|
||||
cursor.seek_forward(&VersionedFullOffset::Offset(range.end), Bias::Left, &cx);
|
||||
let mut end_offset = cursor.start().1;
|
||||
if cursor
|
||||
.item()
|
||||
.map_or(false, |fragment| fragment.is_visible(&self.undo_map))
|
||||
{
|
||||
end_offset += range.end - cursor.start().0.full_offset();
|
||||
}
|
||||
position.add_assign(&rope_cursor.summary(end_offset));
|
||||
start..position.clone()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn edits_since_in_range<'a, D>(
|
||||
&'a self,
|
||||
since: &'a clock::Global,
|
||||
|
Loading…
Reference in New Issue
Block a user