Identify Worktree entries by their inode
This will allow us to re-parent elements when re-scanning when the file system changes.
This commit is contained in:
@@ -105,15 +105,12 @@ impl Pane {
|
||||
self.items.get(self.active_item).cloned()
|
||||
}
|
||||
|
||||
pub fn activate_entry(
|
||||
&mut self,
|
||||
entry_id: (usize, usize),
|
||||
ctx: &mut ViewContext<Self>,
|
||||
) -> bool {
|
||||
if let Some(index) = self.items.iter().position(|item| {
|
||||
item.entry_id(ctx.as_ref())
|
||||
.map_or(false, |id| id == entry_id)
|
||||
}) {
|
||||
pub fn activate_entry(&mut self, entry_id: (usize, u64), ctx: &mut ViewContext<Self>) -> bool {
|
||||
if let Some(index) = self
|
||||
.items
|
||||
.iter()
|
||||
.position(|item| item.entry_id(ctx.as_ref()).map_or(false, |id| id == entry_id))
|
||||
{
|
||||
self.activate_item(index, ctx);
|
||||
true
|
||||
} else {
|
||||
|
||||
@@ -76,7 +76,7 @@ enum OpenedItem {
|
||||
pub struct Workspace {
|
||||
replica_id: ReplicaId,
|
||||
worktrees: HashSet<ModelHandle<Worktree>>,
|
||||
items: HashMap<(usize, usize), OpenedItem>,
|
||||
items: HashMap<(usize, u64), OpenedItem>,
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
@@ -125,7 +125,7 @@ impl Workspace {
|
||||
|
||||
pub fn open_entry(
|
||||
&mut self,
|
||||
entry: (usize, usize),
|
||||
entry: (usize, u64),
|
||||
ctx: &mut ModelContext<'_, Self>,
|
||||
) -> anyhow::Result<Pin<Box<dyn Future<Output = OpenResult> + Send>>> {
|
||||
if let Some(item) = self.items.get(&entry).cloned() {
|
||||
@@ -200,12 +200,12 @@ impl Entity for Workspace {
|
||||
|
||||
#[cfg(test)]
|
||||
pub trait WorkspaceHandle {
|
||||
fn file_entries(&self, app: &AppContext) -> Vec<(usize, usize)>;
|
||||
fn file_entries(&self, app: &AppContext) -> Vec<(usize, u64)>;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl WorkspaceHandle for ModelHandle<Workspace> {
|
||||
fn file_entries(&self, app: &AppContext) -> Vec<(usize, usize)> {
|
||||
fn file_entries(&self, app: &AppContext) -> Vec<(usize, u64)> {
|
||||
self.read(app)
|
||||
.worktrees()
|
||||
.iter()
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn init(app: &mut MutableAppContext) {
|
||||
|
||||
pub trait ItemView: View {
|
||||
fn title(&self, app: &AppContext) -> String;
|
||||
fn entry_id(&self, app: &AppContext) -> Option<(usize, usize)>;
|
||||
fn entry_id(&self, app: &AppContext) -> Option<(usize, u64)>;
|
||||
fn clone_on_split(&self, _: &mut ViewContext<Self>) -> Option<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
@@ -42,7 +42,7 @@ pub trait ItemView: View {
|
||||
|
||||
pub trait ItemViewHandle: Send + Sync {
|
||||
fn title(&self, app: &AppContext) -> String;
|
||||
fn entry_id(&self, app: &AppContext) -> Option<(usize, usize)>;
|
||||
fn entry_id(&self, app: &AppContext) -> Option<(usize, u64)>;
|
||||
fn boxed_clone(&self) -> Box<dyn ItemViewHandle>;
|
||||
fn clone_on_split(&self, app: &mut MutableAppContext) -> Option<Box<dyn ItemViewHandle>>;
|
||||
fn set_parent_pane(&self, pane: &ViewHandle<Pane>, app: &mut MutableAppContext);
|
||||
@@ -57,7 +57,7 @@ impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
|
||||
self.read(app).title(app)
|
||||
}
|
||||
|
||||
fn entry_id(&self, app: &AppContext) -> Option<(usize, usize)> {
|
||||
fn entry_id(&self, app: &AppContext) -> Option<(usize, u64)> {
|
||||
self.read(app).entry_id(app)
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ pub struct WorkspaceView {
|
||||
center: PaneGroup,
|
||||
panes: Vec<ViewHandle<Pane>>,
|
||||
active_pane: ViewHandle<Pane>,
|
||||
loading_entries: HashSet<(usize, usize)>,
|
||||
loading_entries: HashSet<(usize, u64)>,
|
||||
}
|
||||
|
||||
impl WorkspaceView {
|
||||
@@ -189,7 +189,7 @@ impl WorkspaceView {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_entry(&mut self, entry: (usize, usize), ctx: &mut ViewContext<Self>) {
|
||||
pub fn open_entry(&mut self, entry: (usize, u64), ctx: &mut ViewContext<Self>) {
|
||||
if self.loading_entries.contains(&entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user