Merge pull request #563 from zed-industries/mouse-history-navigation
Add missing mouse button events and mouse history navigation
This commit is contained in:
commit
b62daebde1
8 changed files with 238 additions and 32 deletions
|
@ -6,9 +6,9 @@ use gpui::{
|
|||
elements::*,
|
||||
geometry::{rect::RectF, vector::vec2f},
|
||||
keymap::Binding,
|
||||
platform::CursorStyle,
|
||||
platform::{CursorStyle, NavigationDirection},
|
||||
AnyViewHandle, Entity, MutableAppContext, Quad, RenderContext, Task, View, ViewContext,
|
||||
ViewHandle,
|
||||
ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use postage::watch;
|
||||
use project::ProjectPath;
|
||||
|
@ -27,8 +27,8 @@ action!(ActivateNextItem);
|
|||
action!(CloseActiveItem);
|
||||
action!(CloseInactiveItems);
|
||||
action!(CloseItem, usize);
|
||||
action!(GoBack);
|
||||
action!(GoForward);
|
||||
action!(GoBack, Option<WeakViewHandle<Pane>>);
|
||||
action!(GoForward, Option<WeakViewHandle<Pane>>);
|
||||
|
||||
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
|
||||
|
||||
|
@ -54,11 +54,27 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
cx.add_action(|pane: &mut Pane, action: &Split, cx| {
|
||||
pane.split(action.0, cx);
|
||||
});
|
||||
cx.add_action(|workspace: &mut Workspace, _: &GoBack, cx| {
|
||||
Pane::go_back(workspace, cx).detach();
|
||||
cx.add_action(|workspace: &mut Workspace, action: &GoBack, cx| {
|
||||
Pane::go_back(
|
||||
workspace,
|
||||
action
|
||||
.0
|
||||
.as_ref()
|
||||
.and_then(|weak_handle| weak_handle.upgrade(cx)),
|
||||
cx,
|
||||
)
|
||||
.detach();
|
||||
});
|
||||
cx.add_action(|workspace: &mut Workspace, _: &GoForward, cx| {
|
||||
Pane::go_forward(workspace, cx).detach();
|
||||
cx.add_action(|workspace: &mut Workspace, action: &GoForward, cx| {
|
||||
Pane::go_forward(
|
||||
workspace,
|
||||
action
|
||||
.0
|
||||
.as_ref()
|
||||
.and_then(|weak_handle| weak_handle.upgrade(cx)),
|
||||
cx,
|
||||
)
|
||||
.detach();
|
||||
});
|
||||
|
||||
cx.add_bindings(vec![
|
||||
|
@ -70,8 +86,8 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
Binding::new("cmd-k down", Split(SplitDirection::Down), Some("Pane")),
|
||||
Binding::new("cmd-k left", Split(SplitDirection::Left), Some("Pane")),
|
||||
Binding::new("cmd-k right", Split(SplitDirection::Right), Some("Pane")),
|
||||
Binding::new("ctrl--", GoBack, Some("Pane")),
|
||||
Binding::new("shift-ctrl-_", GoForward, Some("Pane")),
|
||||
Binding::new("ctrl--", GoBack(None), Some("Pane")),
|
||||
Binding::new("shift-ctrl-_", GoForward(None), Some("Pane")),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -163,19 +179,27 @@ impl Pane {
|
|||
cx.emit(Event::Activate);
|
||||
}
|
||||
|
||||
pub fn go_back(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> Task<()> {
|
||||
pub fn go_back(
|
||||
workspace: &mut Workspace,
|
||||
pane: Option<ViewHandle<Pane>>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Task<()> {
|
||||
Self::navigate_history(
|
||||
workspace,
|
||||
workspace.active_pane().clone(),
|
||||
pane.unwrap_or_else(|| workspace.active_pane().clone()),
|
||||
NavigationMode::GoingBack,
|
||||
cx,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn go_forward(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> Task<()> {
|
||||
pub fn go_forward(
|
||||
workspace: &mut Workspace,
|
||||
pane: Option<ViewHandle<Pane>>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Task<()> {
|
||||
Self::navigate_history(
|
||||
workspace,
|
||||
workspace.active_pane().clone(),
|
||||
pane.unwrap_or_else(|| workspace.active_pane().clone()),
|
||||
NavigationMode::GoingForward,
|
||||
cx,
|
||||
)
|
||||
|
@ -187,6 +211,8 @@ impl Pane {
|
|||
mode: NavigationMode,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) -> Task<()> {
|
||||
workspace.activate_pane(pane.clone(), cx);
|
||||
|
||||
let to_load = pane.update(cx, |pane, cx| {
|
||||
// Retrieve the weak item handle from the history.
|
||||
let entry = pane.nav_history.borrow_mut().pop(mode)?;
|
||||
|
@ -634,7 +660,9 @@ impl View for Pane {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
if let Some(active_item) = self.active_item() {
|
||||
let this = cx.handle();
|
||||
|
||||
EventHandler::new(if let Some(active_item) = self.active_item() {
|
||||
Flex::column()
|
||||
.with_child(self.render_tabs(cx))
|
||||
.with_children(
|
||||
|
@ -643,10 +671,20 @@ impl View for Pane {
|
|||
.map(|view| ChildView::new(view).boxed()),
|
||||
)
|
||||
.with_child(ChildView::new(active_item).flexible(1., true).boxed())
|
||||
.named("pane")
|
||||
.boxed()
|
||||
} else {
|
||||
Empty::new().named("pane")
|
||||
}
|
||||
Empty::new().boxed()
|
||||
})
|
||||
.on_navigate_mouse_down(move |direction, cx| {
|
||||
let this = this.clone();
|
||||
match direction {
|
||||
NavigationDirection::Back => cx.dispatch_action(GoBack(Some(this))),
|
||||
NavigationDirection::Forward => cx.dispatch_action(GoForward(Some(this))),
|
||||
}
|
||||
|
||||
true
|
||||
})
|
||||
.named("pane")
|
||||
}
|
||||
|
||||
fn on_focus(&mut self, cx: &mut ViewContext<Self>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue