Reintroduce pane navigation history in zed2
This commit is contained in:
parent
bd6fa66a7c
commit
c63ca09eed
2 changed files with 65 additions and 40 deletions
|
@ -529,39 +529,38 @@ fn deserialize_anchor(buffer: &MultiBufferSnapshot, anchor: proto::EditorAnchor)
|
||||||
|
|
||||||
impl Item for Editor {
|
impl Item for Editor {
|
||||||
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
|
fn navigate(&mut self, data: Box<dyn std::any::Any>, cx: &mut ViewContext<Self>) -> bool {
|
||||||
todo!();
|
if let Ok(data) = data.downcast::<NavigationData>() {
|
||||||
// if let Ok(data) = data.downcast::<NavigationData>() {
|
let newest_selection = self.selections.newest::<Point>(cx);
|
||||||
// let newest_selection = self.selections.newest::<Point>(cx);
|
let buffer = self.buffer.read(cx).read(cx);
|
||||||
// let buffer = self.buffer.read(cx).read(cx);
|
let offset = if buffer.can_resolve(&data.cursor_anchor) {
|
||||||
// let offset = if buffer.can_resolve(&data.cursor_anchor) {
|
data.cursor_anchor.to_point(&buffer)
|
||||||
// data.cursor_anchor.to_point(&buffer)
|
} else {
|
||||||
// } else {
|
buffer.clip_point(data.cursor_position, Bias::Left)
|
||||||
// buffer.clip_point(data.cursor_position, Bias::Left)
|
};
|
||||||
// };
|
|
||||||
|
|
||||||
// let mut scroll_anchor = data.scroll_anchor;
|
let mut scroll_anchor = data.scroll_anchor;
|
||||||
// if !buffer.can_resolve(&scroll_anchor.anchor) {
|
if !buffer.can_resolve(&scroll_anchor.anchor) {
|
||||||
// scroll_anchor.anchor = buffer.anchor_before(
|
scroll_anchor.anchor = buffer.anchor_before(
|
||||||
// buffer.clip_point(Point::new(data.scroll_top_row, 0), Bias::Left),
|
buffer.clip_point(Point::new(data.scroll_top_row, 0), Bias::Left),
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// drop(buffer);
|
drop(buffer);
|
||||||
|
|
||||||
// if newest_selection.head() == offset {
|
if newest_selection.head() == offset {
|
||||||
// false
|
false
|
||||||
// } else {
|
} else {
|
||||||
// let nav_history = self.nav_history.take();
|
let nav_history = self.nav_history.take();
|
||||||
// self.set_scroll_anchor(scroll_anchor, cx);
|
self.set_scroll_anchor(scroll_anchor, cx);
|
||||||
// self.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
self.change_selections(Some(Autoscroll::fit()), cx, |s| {
|
||||||
// s.select_ranges([offset..offset])
|
s.select_ranges([offset..offset])
|
||||||
// });
|
});
|
||||||
// self.nav_history = nav_history;
|
self.nav_history = nav_history;
|
||||||
// true
|
true
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// false
|
false
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString> {
|
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString> {
|
||||||
|
|
|
@ -457,6 +457,28 @@ impl Pane {
|
||||||
!self.nav_history.0.lock().forward_stack.is_empty()
|
!self.nav_history.0.lock().forward_stack.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn navigate_backward(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
if let Some(workspace) = self.workspace.upgrade() {
|
||||||
|
let pane = cx.view().downgrade();
|
||||||
|
cx.window_context().defer(move |cx| {
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
workspace.go_back(pane, cx).detach_and_log_err(cx)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn navigate_forward(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
if let Some(workspace) = self.workspace.upgrade() {
|
||||||
|
let pane = cx.view().downgrade();
|
||||||
|
cx.window_context().defer(move |cx| {
|
||||||
|
workspace.update(cx, |workspace, cx| {
|
||||||
|
workspace.go_forward(pane, cx).detach_and_log_err(cx)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn history_updated(&mut self, cx: &mut ViewContext<Self>) {
|
fn history_updated(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
self.toolbar.update(cx, |_, cx| cx.notify());
|
self.toolbar.update(cx, |_, cx| cx.notify());
|
||||||
}
|
}
|
||||||
|
@ -1483,12 +1505,20 @@ impl Pane {
|
||||||
.child(
|
.child(
|
||||||
div().border().border_color(gpui::red()).child(
|
div().border().border_color(gpui::red()).child(
|
||||||
IconButton::new("navigate_backward", Icon::ArrowLeft)
|
IconButton::new("navigate_backward", Icon::ArrowLeft)
|
||||||
|
.on_click({
|
||||||
|
let view = cx.view().clone();
|
||||||
|
move |_, cx| view.update(cx, Self::navigate_backward)
|
||||||
|
})
|
||||||
.disabled(!self.can_navigate_backward()),
|
.disabled(!self.can_navigate_backward()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div().border().border_color(gpui::red()).child(
|
div().border().border_color(gpui::red()).child(
|
||||||
IconButton::new("navigate_forward", Icon::ArrowRight)
|
IconButton::new("navigate_forward", Icon::ArrowRight)
|
||||||
|
.on_click({
|
||||||
|
let view = cx.view().clone();
|
||||||
|
move |_, cx| view.update(cx, Self::navigate_backward)
|
||||||
|
})
|
||||||
.disabled(!self.can_navigate_forward()),
|
.disabled(!self.can_navigate_forward()),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1935,18 +1965,14 @@ impl Render for Pane {
|
||||||
v_stack()
|
v_stack()
|
||||||
.key_context("Pane")
|
.key_context("Pane")
|
||||||
.track_focus(&self.focus_handle)
|
.track_focus(&self.focus_handle)
|
||||||
.on_action(cx.listener(|pane: &mut Pane, _: &SplitLeft, cx| {
|
.on_action(cx.listener(|pane, _: &SplitLeft, cx| pane.split(SplitDirection::Left, cx)))
|
||||||
pane.split(SplitDirection::Left, cx)
|
.on_action(cx.listener(|pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)))
|
||||||
}))
|
|
||||||
.on_action(
|
.on_action(
|
||||||
cx.listener(|pane: &mut Pane, _: &SplitUp, cx| pane.split(SplitDirection::Up, cx)),
|
cx.listener(|pane, _: &SplitRight, cx| pane.split(SplitDirection::Right, cx)),
|
||||||
)
|
)
|
||||||
.on_action(cx.listener(|pane: &mut Pane, _: &SplitRight, cx| {
|
.on_action(cx.listener(|pane, _: &SplitDown, cx| pane.split(SplitDirection::Down, cx)))
|
||||||
pane.split(SplitDirection::Right, cx)
|
.on_action(cx.listener(|pane, _: &GoBack, cx| pane.navigate_backward(cx)))
|
||||||
}))
|
.on_action(cx.listener(|pane, _: &GoForward, cx| pane.navigate_forward(cx)))
|
||||||
.on_action(cx.listener(|pane: &mut Pane, _: &SplitDown, cx| {
|
|
||||||
pane.split(SplitDirection::Down, cx)
|
|
||||||
}))
|
|
||||||
// cx.add_action(Pane::toggle_zoom);
|
// cx.add_action(Pane::toggle_zoom);
|
||||||
// cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
|
// cx.add_action(|pane: &mut Pane, action: &ActivateItem, cx| {
|
||||||
// pane.activate_item(action.0, true, true, cx);
|
// pane.activate_item(action.0, true, true, cx);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue