Preserve cursor position when resetting excerpts (#27850)

Release Notes:

- N/A

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Antonio Scandurra 2025-04-01 18:55:10 +02:00 committed by GitHub
parent f859b328f0
commit 76871056f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 299 additions and 617 deletions

View file

@ -200,14 +200,8 @@ impl FollowableItem for Editor {
buffer_id: buffer.remote_id().into(),
context_start: Some(serialize_text_anchor(&range.context.start)),
context_end: Some(serialize_text_anchor(&range.context.end)),
primary_start: range
.primary
.as_ref()
.map(|range| serialize_text_anchor(&range.start)),
primary_end: range
.primary
.as_ref()
.map(|range| serialize_text_anchor(&range.end)),
primary_start: Some(serialize_text_anchor(&range.primary.start)),
primary_end: Some(serialize_text_anchor(&range.primary.end)),
})
.collect();
@ -481,14 +475,8 @@ fn serialize_excerpt(
buffer_id: buffer_id.into(),
context_start: Some(serialize_text_anchor(&range.context.start)),
context_end: Some(serialize_text_anchor(&range.context.end)),
primary_start: range
.primary
.as_ref()
.map(|r| serialize_text_anchor(&r.start)),
primary_end: range
.primary
.as_ref()
.map(|r| serialize_text_anchor(&r.end)),
primary_start: Some(serialize_text_anchor(&range.primary.start)),
primary_end: Some(serialize_text_anchor(&range.primary.end)),
})
}
@ -521,7 +509,8 @@ fn deserialize_excerpt_range(excerpt: proto::Excerpt) -> Option<ExcerptRange<lan
let start = language::proto::deserialize_anchor(start)?;
let end = language::proto::deserialize_anchor(end)?;
Some(start..end)
});
})
.unwrap_or_else(|| context.clone());
Some(ExcerptRange { context, primary })
}