Match the leader's last selection when unfollowing
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
3e0bc979c3
commit
06cd9ac664
5 changed files with 81 additions and 29 deletions
|
@ -464,7 +464,7 @@ pub struct Editor {
|
|||
pending_rename: Option<RenameState>,
|
||||
searchable: bool,
|
||||
cursor_shape: CursorShape,
|
||||
following: bool,
|
||||
leader_replica_id: Option<u16>,
|
||||
}
|
||||
|
||||
pub struct EditorSnapshot {
|
||||
|
@ -938,7 +938,7 @@ impl Editor {
|
|||
searchable: true,
|
||||
override_text_style: None,
|
||||
cursor_shape: Default::default(),
|
||||
following: false,
|
||||
leader_replica_id: None,
|
||||
};
|
||||
this.end_selection(cx);
|
||||
this
|
||||
|
@ -5038,7 +5038,7 @@ impl Editor {
|
|||
|
||||
self.selections = selections;
|
||||
self.pending_selection = pending_selection;
|
||||
if self.focused && !self.following {
|
||||
if self.focused && self.leader_replica_id.is_none() {
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
buffer.set_active_selections(&self.selections, cx)
|
||||
});
|
||||
|
@ -5673,7 +5673,7 @@ impl View for Editor {
|
|||
self.blink_cursors(self.blink_epoch, cx);
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
buffer.finalize_last_transaction(cx);
|
||||
if !self.following {
|
||||
if self.leader_replica_id.is_none() {
|
||||
buffer.set_active_selections(&self.selections, cx);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Autoscroll, Editor, Event, NavigationData, ToOffset, ToPoint as _};
|
||||
use crate::{Anchor, Autoscroll, Editor, Event, NavigationData, ToOffset, ToPoint as _};
|
||||
use anyhow::{anyhow, Result};
|
||||
use gpui::{
|
||||
elements::*, AppContext, Entity, ModelHandle, MutableAppContext, RenderContext, Subscription,
|
||||
|
@ -50,20 +50,43 @@ impl FollowableItem for Editor {
|
|||
}))
|
||||
}
|
||||
|
||||
fn set_following(&mut self, following: bool, cx: &mut ViewContext<Self>) {
|
||||
self.following = following;
|
||||
if self.following {
|
||||
fn set_leader_replica_id(
|
||||
&mut self,
|
||||
leader_replica_id: Option<u16>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let prev_leader_replica_id = self.leader_replica_id;
|
||||
self.leader_replica_id = leader_replica_id;
|
||||
if self.leader_replica_id.is_some() {
|
||||
self.show_local_selections = false;
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
buffer.remove_active_selections(cx);
|
||||
});
|
||||
} else {
|
||||
self.show_local_selections = true;
|
||||
if self.focused {
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
buffer.set_active_selections(&self.selections, cx);
|
||||
});
|
||||
if let Some(leader_replica_id) = prev_leader_replica_id {
|
||||
let selections = self
|
||||
.buffer
|
||||
.read(cx)
|
||||
.snapshot(cx)
|
||||
.remote_selections_in_range(&(Anchor::min()..Anchor::max()))
|
||||
.filter_map(|(replica_id, selections)| {
|
||||
if replica_id == leader_replica_id {
|
||||
Some(selections)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
if !selections.is_empty() {
|
||||
self.set_selections(selections.into(), None, cx);
|
||||
}
|
||||
}
|
||||
self.buffer.update(cx, |buffer, cx| {
|
||||
if self.focused {
|
||||
buffer.set_active_selections(&self.selections, cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue