Restore the ability to search terminals in the terminal panel (#2528)

Fixes
https://linear.app/zed-industries/issue/Z-1812/find-in-terminal-panel-is-broken

![CleanShot 2023-05-25 at 15 18
01@2x](https://github.com/zed-industries/zed/assets/482957/ddb33b61-d253-4de1-961f-14b24aaa3e46)

This also removes navigation controls from the terminal panel, given
that terminals don't make use of that feature anyway. When the toolbar
is empty, we'll avoid showing it altogether.

![CleanShot 2023-05-25 at 15 17
26@2x](https://github.com/zed-industries/zed/assets/482957/52419f2c-bca0-494a-a9b3-88e183b4c12f)


Release Notes:

- Fixed a regression that was preventing the terminal panel from being
searched.
This commit is contained in:
Antonio Scandurra 2023-05-25 15:28:32 +02:00 committed by GitHub
commit f549ada54f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 103 additions and 66 deletions

1
Cargo.lock generated
View file

@ -6809,6 +6809,7 @@ dependencies = [
"procinfo", "procinfo",
"project", "project",
"rand 0.8.5", "rand 0.8.5",
"search",
"serde", "serde",
"serde_derive", "serde_derive",
"settings", "settings",

View file

@ -14,6 +14,7 @@ editor = { path = "../editor" }
language = { path = "../language" } language = { path = "../language" }
gpui = { path = "../gpui" } gpui = { path = "../gpui" }
project = { path = "../project" } project = { path = "../project" }
search = { path = "../search" }
settings = { path = "../settings" } settings = { path = "../settings" }
theme = { path = "../theme" } theme = { path = "../theme" }
util = { path = "../util" } util = { path = "../util" }

View file

@ -55,6 +55,7 @@ impl TerminalPanel {
cx, cx,
); );
pane.set_can_split(false, cx); pane.set_can_split(false, cx);
pane.set_can_navigate(false, cx);
pane.on_can_drop(move |drag_and_drop, cx| { pane.on_can_drop(move |drag_and_drop, cx| {
drag_and_drop drag_and_drop
.currently_dragged::<DraggedItem>(window_id) .currently_dragged::<DraggedItem>(window_id)
@ -99,6 +100,9 @@ impl TerminalPanel {
)) ))
.into_any() .into_any()
}); });
let buffer_search_bar = cx.add_view(search::BufferSearchBar::new);
pane.toolbar()
.update(cx, |toolbar, cx| toolbar.add_item(buffer_search_bar, cx));
pane pane
}); });
let subscriptions = vec![ let subscriptions = vec![

View file

@ -164,6 +164,7 @@ pub struct Pane {
has_focus: bool, has_focus: bool,
can_drop: Rc<dyn Fn(&DragAndDrop<Workspace>, &WindowContext) -> bool>, can_drop: Rc<dyn Fn(&DragAndDrop<Workspace>, &WindowContext) -> bool>,
can_split: bool, can_split: bool,
can_navigate: bool,
render_tab_bar_buttons: Rc<dyn Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>>, render_tab_bar_buttons: Rc<dyn Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>>,
} }
@ -279,6 +280,7 @@ impl Pane {
has_focus: false, has_focus: false,
can_drop: Rc::new(|_, _| true), can_drop: Rc::new(|_, _| true),
can_split: true, can_split: true,
can_navigate: true,
render_tab_bar_buttons: Rc::new(|pane, cx| { render_tab_bar_buttons: Rc::new(|pane, cx| {
Flex::row() Flex::row()
// New menu // New menu
@ -346,6 +348,14 @@ impl Pane {
cx.notify(); cx.notify();
} }
pub fn set_can_navigate(&mut self, can_navigate: bool, cx: &mut ViewContext<Self>) {
self.can_navigate = can_navigate;
self.toolbar.update(cx, |toolbar, cx| {
toolbar.set_can_navigate(can_navigate, cx);
});
cx.notify();
}
pub fn set_render_tab_bar_buttons<F>(&mut self, cx: &mut ViewContext<Self>, render: F) pub fn set_render_tab_bar_buttons<F>(&mut self, cx: &mut ViewContext<Self>, render: F)
where where
F: 'static + Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>, F: 'static + Fn(&mut Pane, &mut ViewContext<Pane>) -> AnyElement<Pane>,
@ -430,6 +440,10 @@ impl Pane {
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
let to_load = if let Some(pane) = pane.upgrade(cx) { let to_load = if let Some(pane) = pane.upgrade(cx) {
if !pane.read(cx).can_navigate {
return Task::ready(Ok(()));
}
cx.focus(&pane); cx.focus(&pane);
pane.update(cx, |pane, cx| { pane.update(cx, |pane, cx| {

View file

@ -53,6 +53,7 @@ pub enum ToolbarItemLocation {
pub struct Toolbar { pub struct Toolbar {
active_pane_item: Option<Box<dyn ItemHandle>>, active_pane_item: Option<Box<dyn ItemHandle>>,
hidden: bool, hidden: bool,
can_navigate: bool,
pane: WeakViewHandle<Pane>, pane: WeakViewHandle<Pane>,
items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>, items: Vec<(Box<dyn ToolbarItemViewHandle>, ToolbarItemLocation)>,
} }
@ -132,10 +133,9 @@ impl View for Toolbar {
let button_style = theme.nav_button; let button_style = theme.nav_button;
let tooltip_style = theme::current(cx).tooltip.clone(); let tooltip_style = theme::current(cx).tooltip.clone();
Flex::column() let mut primary_items = Flex::row();
.with_child( if self.can_navigate {
Flex::row() primary_items.add_child(nav_button(
.with_child(nav_button(
"icons/arrow_left_16.svg", "icons/arrow_left_16.svg",
button_style, button_style,
nav_button_height, nav_button_height,
@ -163,8 +163,8 @@ impl View for Toolbar {
super::GoBack { pane: None }, super::GoBack { pane: None },
"Go Back", "Go Back",
cx, cx,
)) ));
.with_child(nav_button( primary_items.add_child(nav_button(
"icons/arrow_right_16.svg", "icons/arrow_right_16.svg",
button_style, button_style,
nav_button_height, nav_button_height,
@ -192,17 +192,28 @@ impl View for Toolbar {
super::GoForward { pane: None }, super::GoForward { pane: None },
"Go Forward", "Go Forward",
cx, cx,
)) ));
.with_children(primary_left_items) }
.with_children(primary_right_items) primary_items.extend(primary_left_items);
.constrained() primary_items.extend(primary_right_items);
.with_height(height),
) let mut toolbar = Flex::column();
.with_children(secondary_item) if !primary_items.is_empty() {
toolbar.add_child(primary_items.constrained().with_height(height));
}
if let Some(secondary_item) = secondary_item {
toolbar.add_child(secondary_item);
}
if toolbar.is_empty() {
toolbar.into_any_named("toolbar")
} else {
toolbar
.contained() .contained()
.with_style(container_style) .with_style(container_style)
.into_any_named("toolbar") .into_any_named("toolbar")
} }
}
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
@ -264,9 +275,15 @@ impl Toolbar {
pane, pane,
items: Default::default(), items: Default::default(),
hidden: false, hidden: false,
can_navigate: true,
} }
} }
pub fn set_can_navigate(&mut self, can_navigate: bool, cx: &mut ViewContext<Self>) {
self.can_navigate = can_navigate;
cx.notify();
}
pub fn add_item<T>(&mut self, item: ViewHandle<T>, cx: &mut ViewContext<Self>) pub fn add_item<T>(&mut self, item: ViewHandle<T>, cx: &mut ViewContext<Self>)
where where
T: 'static + ToolbarItemView, T: 'static + ToolbarItemView,