WIP
This commit is contained in:
parent
255a8c5d14
commit
5cd94b5b92
5 changed files with 61 additions and 44 deletions
|
@ -454,9 +454,9 @@ impl workspace::Item for ProjectDiagnosticsEditor {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigate(&mut self, data: Box<dyn Any>, cx: &mut ViewContext<Self>) {
|
fn navigate(&mut self, data: Box<dyn Any>, cx: &mut ViewContext<Self>) -> bool {
|
||||||
self.editor
|
self.editor
|
||||||
.update(cx, |editor, cx| editor.navigate(data, cx));
|
.update(cx, |editor, cx| editor.navigate(data, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_dirty(&self, cx: &AppContext) -> bool {
|
fn is_dirty(&self, cx: &AppContext) -> bool {
|
||||||
|
|
|
@ -241,7 +241,7 @@ fn deserialize_selection(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Item for Editor {
|
impl Item for Editor {
|
||||||
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) {
|
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
|
||||||
if let Some(data) = data.downcast_ref::<NavigationData>() {
|
if let Some(data) = data.downcast_ref::<NavigationData>() {
|
||||||
let buffer = self.buffer.read(cx).read(cx);
|
let buffer = self.buffer.read(cx).read(cx);
|
||||||
let offset = if buffer.can_resolve(&data.anchor) {
|
let offset = if buffer.can_resolve(&data.anchor) {
|
||||||
|
@ -249,11 +249,19 @@ impl Item for Editor {
|
||||||
} else {
|
} else {
|
||||||
buffer.clip_offset(data.offset, Bias::Left)
|
buffer.clip_offset(data.offset, Bias::Left)
|
||||||
};
|
};
|
||||||
|
let newest_selection = self.newest_selection_with_snapshot::<usize>(&buffer);
|
||||||
drop(buffer);
|
drop(buffer);
|
||||||
|
|
||||||
|
if newest_selection.head() == offset {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
let nav_history = self.nav_history.take();
|
let nav_history = self.nav_history.take();
|
||||||
self.select_ranges([offset..offset], Some(Autoscroll::Fit), cx);
|
self.select_ranges([offset..offset], Some(Autoscroll::Fit), cx);
|
||||||
self.nav_history = nav_history;
|
self.nav_history = nav_history;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -302,9 +302,9 @@ impl Item for ProjectSearchView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigate(&mut self, data: Box<dyn Any>, cx: &mut ViewContext<Self>) {
|
fn navigate(&mut self, data: Box<dyn Any>, cx: &mut ViewContext<Self>) -> bool {
|
||||||
self.results_editor
|
self.results_editor
|
||||||
.update(cx, |editor, cx| editor.navigate(data, cx));
|
.update(cx, |editor, cx| editor.navigate(data, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_update_tab_on_event(event: &ViewEvent) -> bool {
|
fn should_update_tab_on_event(event: &ViewEvent) -> bool {
|
||||||
|
|
|
@ -212,6 +212,7 @@ impl Pane {
|
||||||
workspace.activate_pane(pane.clone(), cx);
|
workspace.activate_pane(pane.clone(), cx);
|
||||||
|
|
||||||
let to_load = pane.update(cx, |pane, cx| {
|
let to_load = pane.update(cx, |pane, cx| {
|
||||||
|
loop {
|
||||||
// Retrieve the weak item handle from the history.
|
// Retrieve the weak item handle from the history.
|
||||||
let entry = pane.nav_history.borrow_mut().pop(mode)?;
|
let entry = pane.nav_history.borrow_mut().pop(mode)?;
|
||||||
|
|
||||||
|
@ -229,23 +230,29 @@ impl Pane {
|
||||||
.set_mode(NavigationMode::Normal);
|
.set_mode(NavigationMode::Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
pane.active_item_index = index;
|
let prev_active_index = mem::replace(&mut pane.active_item_index, index);
|
||||||
pane.focus_active_item(cx);
|
pane.focus_active_item(cx);
|
||||||
|
let mut navigated = prev_active_index != pane.active_item_index;
|
||||||
if let Some(data) = entry.data {
|
if let Some(data) = entry.data {
|
||||||
pane.active_item()?.navigate(data, cx);
|
navigated |= pane.active_item()?.navigate(data, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if navigated {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
None
|
break None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If the item is no longer present in this pane, then retrieve its
|
// If the item is no longer present in this pane, then retrieve its
|
||||||
// project path in order to reopen it.
|
// project path in order to reopen it.
|
||||||
else {
|
else {
|
||||||
pane.nav_history
|
break pane
|
||||||
|
.nav_history
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.paths_by_item
|
.paths_by_item
|
||||||
.get(&entry.item.id())
|
.get(&entry.item.id())
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|project_path| (project_path, entry))
|
.map(|project_path| (project_path, entry));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,9 @@ pub struct JoinProjectParams {
|
||||||
|
|
||||||
pub trait Item: View {
|
pub trait Item: View {
|
||||||
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
fn deactivated(&mut self, _: &mut ViewContext<Self>) {}
|
||||||
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) {}
|
fn navigate(&mut self, _: Box<dyn Any>, _: &mut ViewContext<Self>) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
|
fn tab_content(&self, style: &theme::Tab, cx: &AppContext) -> ElementBox;
|
||||||
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
|
||||||
fn project_entry_id(&self, cx: &AppContext) -> Option<ProjectEntryId>;
|
fn project_entry_id(&self, cx: &AppContext) -> Option<ProjectEntryId>;
|
||||||
|
@ -362,7 +364,7 @@ pub trait ItemHandle: 'static + fmt::Debug {
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
);
|
);
|
||||||
fn deactivated(&self, cx: &mut MutableAppContext);
|
fn deactivated(&self, cx: &mut MutableAppContext);
|
||||||
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext);
|
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool;
|
||||||
fn id(&self) -> usize;
|
fn id(&self) -> usize;
|
||||||
fn to_any(&self) -> AnyViewHandle;
|
fn to_any(&self) -> AnyViewHandle;
|
||||||
fn is_dirty(&self, cx: &AppContext) -> bool;
|
fn is_dirty(&self, cx: &AppContext) -> bool;
|
||||||
|
@ -510,8 +512,8 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||||
self.update(cx, |this, cx| this.deactivated(cx));
|
self.update(cx, |this, cx| this.deactivated(cx));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) {
|
fn navigate(&self, data: Box<dyn Any>, cx: &mut MutableAppContext) -> bool {
|
||||||
self.update(cx, |this, cx| this.navigate(data, cx));
|
self.update(cx, |this, cx| this.navigate(data, cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save(&self, project: ModelHandle<Project>, cx: &mut MutableAppContext) -> Task<Result<()>> {
|
fn save(&self, project: ModelHandle<Project>, cx: &mut MutableAppContext) -> Task<Result<()>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue