Fix panic in set_scroll_anchor_remote (#3987)

If the remote sends us an invalid scroll position, we should not panic.

Release Notes:

- Fix a panic receiving scroll positions out of order
This commit is contained in:
Conrad Irwin 2024-01-09 14:39:06 -07:00 committed by GitHub
commit 0daa2bf7f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -384,10 +384,12 @@ impl Editor {
) {
hide_hover(self, cx);
let workspace_id = self.workspace.as_ref().map(|workspace| workspace.1);
let top_row = scroll_anchor
.anchor
.to_point(&self.buffer().read(cx).snapshot(cx))
.row;
let snapshot = &self.buffer().read(cx).snapshot(cx);
if !scroll_anchor.anchor.is_valid(snapshot) {
log::warn!("Invalid scroll anchor: {:?}", scroll_anchor);
return;
}
let top_row = scroll_anchor.anchor.to_point(snapshot).row;
self.scroll_manager
.set_anchor(scroll_anchor, top_row, false, false, workspace_id, cx);
}