Allow splitting the terminal panel (#21238)
Closes https://github.com/zed-industries/zed/issues/4351  Applies the same splitting mechanism, as Zed's central pane has, to the terminal panel. Similar navigation, splitting and (de)serialization capabilities are supported. Notable caveats: * zooming keeps the terminal splits' ratio, rather expanding the terminal pane * on macOs, central panel is split with `cmd-k up/down/etc.` but `cmd-k` is a "standard" terminal clearing keybinding on macOS, so terminal panel splitting is done via `ctrl-k up/down/etc.` * task terminals are "split" into regular terminals, and also not persisted (same as currently in the terminal) Seems ok for the initial version, we can revisit and polish things later. Release Notes: - Added the ability to split the terminal panel
This commit is contained in:
parent
4564da2875
commit
d0bafce86b
17 changed files with 953 additions and 348 deletions
|
@ -291,7 +291,7 @@ pub struct Pane {
|
|||
can_drop_predicate: Option<Arc<dyn Fn(&dyn Any, &mut WindowContext) -> bool>>,
|
||||
custom_drop_handle:
|
||||
Option<Arc<dyn Fn(&mut Pane, &dyn Any, &mut ViewContext<Pane>) -> ControlFlow<(), ()>>>,
|
||||
can_split: bool,
|
||||
can_split_predicate: Option<Arc<dyn Fn(&mut Self, &dyn Any, &mut ViewContext<Self>) -> bool>>,
|
||||
should_display_tab_bar: Rc<dyn Fn(&ViewContext<Pane>) -> bool>,
|
||||
render_tab_bar_buttons:
|
||||
Rc<dyn Fn(&mut Pane, &mut ViewContext<Pane>) -> (Option<AnyElement>, Option<AnyElement>)>,
|
||||
|
@ -411,7 +411,7 @@ impl Pane {
|
|||
project,
|
||||
can_drop_predicate,
|
||||
custom_drop_handle: None,
|
||||
can_split: true,
|
||||
can_split_predicate: None,
|
||||
should_display_tab_bar: Rc::new(|cx| TabBarSettings::get_global(cx).show),
|
||||
render_tab_bar_buttons: Rc::new(move |pane, cx| {
|
||||
if !pane.has_focus(cx) && !pane.context_menu_focused(cx) {
|
||||
|
@ -623,9 +623,13 @@ impl Pane {
|
|||
self.should_display_tab_bar = Rc::new(should_display_tab_bar);
|
||||
}
|
||||
|
||||
pub fn set_can_split(&mut self, can_split: bool, cx: &mut ViewContext<Self>) {
|
||||
self.can_split = can_split;
|
||||
cx.notify();
|
||||
pub fn set_can_split(
|
||||
&mut self,
|
||||
can_split_predicate: Option<
|
||||
Arc<dyn Fn(&mut Self, &dyn Any, &mut ViewContext<Self>) -> bool + 'static>,
|
||||
>,
|
||||
) {
|
||||
self.can_split_predicate = can_split_predicate;
|
||||
}
|
||||
|
||||
pub fn set_can_navigate(&mut self, can_navigate: bool, cx: &mut ViewContext<Self>) {
|
||||
|
@ -2384,8 +2388,18 @@ impl Pane {
|
|||
self.zoomed
|
||||
}
|
||||
|
||||
fn handle_drag_move<T>(&mut self, event: &DragMoveEvent<T>, cx: &mut ViewContext<Self>) {
|
||||
if !self.can_split {
|
||||
fn handle_drag_move<T: 'static>(
|
||||
&mut self,
|
||||
event: &DragMoveEvent<T>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
let can_split_predicate = self.can_split_predicate.take();
|
||||
let can_split = match &can_split_predicate {
|
||||
Some(can_split_predicate) => can_split_predicate(self, event.dragged_item(), cx),
|
||||
None => false,
|
||||
};
|
||||
self.can_split_predicate = can_split_predicate;
|
||||
if !can_split {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2679,6 +2693,10 @@ impl Pane {
|
|||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn drag_split_direction(&self) -> Option<SplitDirection> {
|
||||
self.drag_split_direction
|
||||
}
|
||||
}
|
||||
|
||||
impl FocusableView for Pane {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue