mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-28 23:51:36 +03:00
Introduce pane::ReopenClosedItem
bound to cmd-shift-t
This commit is contained in:
parent
024dfd760c
commit
0652542f60
@ -212,6 +212,7 @@
|
|||||||
"bindings": {
|
"bindings": {
|
||||||
"ctrl--": "pane::GoBack",
|
"ctrl--": "pane::GoBack",
|
||||||
"shift-ctrl-_": "pane::GoForward",
|
"shift-ctrl-_": "pane::GoForward",
|
||||||
|
"cmd-shift-T": "pane::ReopenClosedItem",
|
||||||
"cmd-shift-F": "project_search::ToggleFocus"
|
"cmd-shift-F": "project_search::ToggleFocus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -25,6 +25,7 @@ actions!(
|
|||||||
ActivateNextItem,
|
ActivateNextItem,
|
||||||
CloseActiveItem,
|
CloseActiveItem,
|
||||||
CloseInactiveItems,
|
CloseInactiveItems,
|
||||||
|
ReopenClosedItem,
|
||||||
SplitLeft,
|
SplitLeft,
|
||||||
SplitUp,
|
SplitUp,
|
||||||
SplitRight,
|
SplitRight,
|
||||||
@ -82,6 +83,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||||||
cx.add_action(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx));
|
cx.add_action(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx));
|
||||||
cx.add_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx));
|
cx.add_action(|pane: &mut Pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx));
|
||||||
cx.add_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx));
|
cx.add_action(|pane: &mut Pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx));
|
||||||
|
cx.add_action(Pane::reopen_closed_item);
|
||||||
cx.add_action(|workspace: &mut Workspace, action: &GoBack, cx| {
|
cx.add_action(|workspace: &mut Workspace, action: &GoBack, cx| {
|
||||||
Pane::go_back(
|
Pane::go_back(
|
||||||
workspace,
|
workspace,
|
||||||
@ -133,6 +135,7 @@ pub struct NavHistory {
|
|||||||
mode: NavigationMode,
|
mode: NavigationMode,
|
||||||
backward_stack: VecDeque<NavigationEntry>,
|
backward_stack: VecDeque<NavigationEntry>,
|
||||||
forward_stack: VecDeque<NavigationEntry>,
|
forward_stack: VecDeque<NavigationEntry>,
|
||||||
|
closed_stack: VecDeque<NavigationEntry>,
|
||||||
paths_by_item: HashMap<usize, ProjectPath>,
|
paths_by_item: HashMap<usize, ProjectPath>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +144,8 @@ enum NavigationMode {
|
|||||||
Normal,
|
Normal,
|
||||||
GoingBack,
|
GoingBack,
|
||||||
GoingForward,
|
GoingForward,
|
||||||
|
ClosingItem,
|
||||||
|
ReopeningClosed,
|
||||||
Disabled,
|
Disabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,6 +205,20 @@ impl Pane {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reopen_closed_item(
|
||||||
|
workspace: &mut Workspace,
|
||||||
|
_: &ReopenClosedItem,
|
||||||
|
cx: &mut ViewContext<Workspace>,
|
||||||
|
) {
|
||||||
|
Self::navigate_history(
|
||||||
|
workspace,
|
||||||
|
workspace.active_pane().clone(),
|
||||||
|
NavigationMode::ReopeningClosed,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.detach();
|
||||||
|
}
|
||||||
|
|
||||||
fn navigate_history(
|
fn navigate_history(
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
pane: ViewHandle<Pane>,
|
pane: ViewHandle<Pane>,
|
||||||
@ -240,7 +259,7 @@ impl Pane {
|
|||||||
else {
|
else {
|
||||||
break pane
|
break pane
|
||||||
.nav_history
|
.nav_history
|
||||||
.borrow_mut()
|
.borrow()
|
||||||
.paths_by_item
|
.paths_by_item
|
||||||
.get(&entry.item.id())
|
.get(&entry.item.id())
|
||||||
.cloned()
|
.cloned()
|
||||||
@ -256,10 +275,13 @@ impl Pane {
|
|||||||
cx.spawn(|workspace, mut cx| async move {
|
cx.spawn(|workspace, mut cx| async move {
|
||||||
let task = task.await;
|
let task = task.await;
|
||||||
if let Some(pane) = pane.upgrade(&cx) {
|
if let Some(pane) = pane.upgrade(&cx) {
|
||||||
|
let mut navigated = false;
|
||||||
if let Some((project_entry_id, build_item)) = task.log_err() {
|
if let Some((project_entry_id, build_item)) = task.log_err() {
|
||||||
pane.update(&mut cx, |pane, _| {
|
let prev_active_item_id = pane.update(&mut cx, |pane, _| {
|
||||||
pane.nav_history.borrow_mut().set_mode(mode);
|
pane.nav_history.borrow_mut().set_mode(mode);
|
||||||
|
pane.active_item().map(|p| p.id())
|
||||||
});
|
});
|
||||||
|
|
||||||
let item = workspace.update(&mut cx, |workspace, cx| {
|
let item = workspace.update(&mut cx, |workspace, cx| {
|
||||||
Self::open_item(
|
Self::open_item(
|
||||||
workspace,
|
workspace,
|
||||||
@ -270,15 +292,19 @@ impl Pane {
|
|||||||
build_item,
|
build_item,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
pane.update(&mut cx, |pane, cx| {
|
pane.update(&mut cx, |pane, cx| {
|
||||||
|
navigated |= Some(item.id()) != prev_active_item_id;
|
||||||
pane.nav_history
|
pane.nav_history
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.set_mode(NavigationMode::Normal);
|
.set_mode(NavigationMode::Normal);
|
||||||
if let Some(data) = entry.data {
|
if let Some(data) = entry.data {
|
||||||
item.navigate(data, cx);
|
navigated |= item.navigate(data, cx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if !navigated {
|
||||||
workspace
|
workspace
|
||||||
.update(&mut cx, |workspace, cx| {
|
.update(&mut cx, |workspace, cx| {
|
||||||
Self::navigate_history(workspace, pane, mode, cx)
|
Self::navigate_history(workspace, pane, mode, cx)
|
||||||
@ -587,7 +613,15 @@ impl Pane {
|
|||||||
pane.active_item_index -= 1;
|
pane.active_item_index -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut nav_history = pane.nav_history.borrow_mut();
|
pane.nav_history
|
||||||
|
.borrow_mut()
|
||||||
|
.set_mode(NavigationMode::ClosingItem);
|
||||||
|
item.deactivated(cx);
|
||||||
|
pane.nav_history
|
||||||
|
.borrow_mut()
|
||||||
|
.set_mode(NavigationMode::Normal);
|
||||||
|
|
||||||
|
let mut nav_history = pane.nav_history().borrow_mut();
|
||||||
if let Some(path) = item.project_path(cx) {
|
if let Some(path) = item.project_path(cx) {
|
||||||
nav_history.paths_by_item.insert(item.id(), path);
|
nav_history.paths_by_item.insert(item.id(), path);
|
||||||
} else {
|
} else {
|
||||||
@ -925,11 +959,16 @@ impl NavHistory {
|
|||||||
self.forward_stack.pop_back()
|
self.forward_stack.pop_back()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pop_closed(&mut self) -> Option<NavigationEntry> {
|
||||||
|
self.closed_stack.pop_back()
|
||||||
|
}
|
||||||
|
|
||||||
fn pop(&mut self, mode: NavigationMode) -> Option<NavigationEntry> {
|
fn pop(&mut self, mode: NavigationMode) -> Option<NavigationEntry> {
|
||||||
match mode {
|
match mode {
|
||||||
NavigationMode::Normal | NavigationMode::Disabled => None,
|
NavigationMode::Normal | NavigationMode::Disabled | NavigationMode::ClosingItem => None,
|
||||||
NavigationMode::GoingBack => self.pop_backward(),
|
NavigationMode::GoingBack => self.pop_backward(),
|
||||||
NavigationMode::GoingForward => self.pop_forward(),
|
NavigationMode::GoingForward => self.pop_forward(),
|
||||||
|
NavigationMode::ReopeningClosed => self.pop_closed(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -940,7 +979,7 @@ impl NavHistory {
|
|||||||
pub fn push<D: 'static + Any>(&mut self, data: Option<D>, item: Rc<dyn WeakItemHandle>) {
|
pub fn push<D: 'static + Any>(&mut self, data: Option<D>, item: Rc<dyn WeakItemHandle>) {
|
||||||
match self.mode {
|
match self.mode {
|
||||||
NavigationMode::Disabled => {}
|
NavigationMode::Disabled => {}
|
||||||
NavigationMode::Normal => {
|
NavigationMode::Normal | NavigationMode::ReopeningClosed => {
|
||||||
if self.backward_stack.len() >= MAX_NAVIGATION_HISTORY_LEN {
|
if self.backward_stack.len() >= MAX_NAVIGATION_HISTORY_LEN {
|
||||||
self.backward_stack.pop_front();
|
self.backward_stack.pop_front();
|
||||||
}
|
}
|
||||||
@ -968,6 +1007,15 @@ impl NavHistory {
|
|||||||
data: data.map(|data| Box::new(data) as Box<dyn Any>),
|
data: data.map(|data| Box::new(data) as Box<dyn Any>),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
NavigationMode::ClosingItem => {
|
||||||
|
if self.closed_stack.len() >= MAX_NAVIGATION_HISTORY_LEN {
|
||||||
|
self.closed_stack.pop_front();
|
||||||
|
}
|
||||||
|
self.closed_stack.push_back(NavigationEntry {
|
||||||
|
item,
|
||||||
|
data: data.map(|data| Box::new(data) as Box<dyn Any>),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user