Synchronize modal commit editor with panel editor (#26068)

Release Notes:

- Git Beta: Synchronized selections between the modal editor and the
panel editor
- Git Beta: Allow opening the commit modal even if we're unable to
commit.
This commit is contained in:
Mikayla Maki 2025-03-04 13:58:26 -08:00 committed by GitHub
parent 0a2d938ac5
commit ebc5c213a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 83 additions and 30 deletions

View file

@ -2233,6 +2233,43 @@ impl Editor {
cx.notify();
}
pub fn sync_selections(
&mut self,
other: Entity<Editor>,
cx: &mut Context<Self>,
) -> gpui::Subscription {
let other_selections = other.read(cx).selections.disjoint.to_vec();
self.selections.change_with(cx, |selections| {
selections.select_anchors(other_selections);
});
let other_subscription =
cx.subscribe(&other, |this, other, other_evt, cx| match other_evt {
EditorEvent::SelectionsChanged { local: true } => {
let other_selections = other.read(cx).selections.disjoint.to_vec();
this.selections.change_with(cx, |selections| {
selections.select_anchors(other_selections);
});
}
_ => {}
});
let this_subscription =
cx.subscribe_self::<EditorEvent>(move |this, this_evt, cx| match this_evt {
EditorEvent::SelectionsChanged { local: true } => {
let these_selections = this.selections.disjoint.to_vec();
other.update(cx, |other_editor, cx| {
other_editor.selections.change_with(cx, |selections| {
selections.select_anchors(these_selections);
})
});
}
_ => {}
});
Subscription::join(other_subscription, this_subscription)
}
pub fn change_selections<R>(
&mut self,
autoscroll: Option<Autoscroll>,