Allow splitting the terminal panel (#21238)

Closes https://github.com/zed-industries/zed/issues/4351


![it_splits](https://github.com/user-attachments/assets/40de03c9-2173-4441-ba96-8e91537956e0)

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:
Kirill Bulatov 2024-11-27 20:22:39 +02:00 committed by GitHub
parent 4564da2875
commit d0bafce86b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 953 additions and 348 deletions

View file

@ -27,11 +27,11 @@ const VERTICAL_MIN_SIZE: f32 = 100.;
/// Single-pane group is a regular pane.
#[derive(Clone)]
pub struct PaneGroup {
pub(crate) root: Member,
pub root: Member,
}
impl PaneGroup {
pub(crate) fn with_root(root: Member) -> Self {
pub fn with_root(root: Member) -> Self {
Self { root }
}
@ -122,7 +122,7 @@ impl PaneGroup {
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn render(
pub fn render(
&self,
project: &Model<Project>,
follower_states: &HashMap<PeerId, FollowerState>,
@ -144,19 +144,51 @@ impl PaneGroup {
)
}
pub(crate) fn panes(&self) -> Vec<&View<Pane>> {
pub fn panes(&self) -> Vec<&View<Pane>> {
let mut panes = Vec::new();
self.root.collect_panes(&mut panes);
panes
}
pub(crate) fn first_pane(&self) -> View<Pane> {
pub fn first_pane(&self) -> View<Pane> {
self.root.first_pane()
}
pub fn find_pane_in_direction(
&mut self,
active_pane: &View<Pane>,
direction: SplitDirection,
cx: &WindowContext,
) -> Option<&View<Pane>> {
let bounding_box = self.bounding_box_for_pane(active_pane)?;
let cursor = active_pane.read(cx).pixel_position_of_cursor(cx);
let center = match cursor {
Some(cursor) if bounding_box.contains(&cursor) => cursor,
_ => bounding_box.center(),
};
let distance_to_next = crate::HANDLE_HITBOX_SIZE;
let target = match direction {
SplitDirection::Left => {
Point::new(bounding_box.left() - distance_to_next.into(), center.y)
}
SplitDirection::Right => {
Point::new(bounding_box.right() + distance_to_next.into(), center.y)
}
SplitDirection::Up => {
Point::new(center.x, bounding_box.top() - distance_to_next.into())
}
SplitDirection::Down => {
Point::new(center.x, bounding_box.bottom() + distance_to_next.into())
}
};
self.pane_at_pixel_position(target)
}
}
#[derive(Clone)]
pub(crate) enum Member {
#[derive(Debug, Clone)]
pub enum Member {
Axis(PaneAxis),
Pane(View<Pane>),
}
@ -359,8 +391,8 @@ impl Member {
}
}
#[derive(Clone)]
pub(crate) struct PaneAxis {
#[derive(Debug, Clone)]
pub struct PaneAxis {
pub axis: Axis,
pub members: Vec<Member>,
pub flexes: Arc<Mutex<Vec<f32>>>,