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
17 changed files with 953 additions and 348 deletions
+1 -1
View File
@@ -1578,7 +1578,7 @@ pub struct AnyDrag {
pub view: AnyView,
/// The value of the dragged item, to be dropped
pub value: Box<dyn Any>,
pub value: Arc<dyn Any>,
/// This is used to render the dragged item in the same place
/// on the original element that the drag was initiated
+23 -16
View File
@@ -35,6 +35,7 @@ use std::{
mem,
ops::DerefMut,
rc::Rc,
sync::Arc,
time::Duration,
};
use taffy::style::Overflow;
@@ -61,6 +62,7 @@ pub struct DragMoveEvent<T> {
/// The bounds of this element.
pub bounds: Bounds<Pixels>,
drag: PhantomData<T>,
dragged_item: Arc<dyn Any>,
}
impl<T: 'static> DragMoveEvent<T> {
@@ -71,6 +73,11 @@ impl<T: 'static> DragMoveEvent<T> {
.and_then(|drag| drag.value.downcast_ref::<T>())
.expect("DragMoveEvent is only valid when the stored active drag is of the same type.")
}
/// An item that is about to be dropped.
pub fn dragged_item(&self) -> &dyn Any {
self.dragged_item.as_ref()
}
}
impl Interactivity {
@@ -243,20 +250,20 @@ impl Interactivity {
{
self.mouse_move_listeners
.push(Box::new(move |event, phase, hitbox, cx| {
if phase == DispatchPhase::Capture
&& cx
.active_drag
.as_ref()
.is_some_and(|drag| drag.value.as_ref().type_id() == TypeId::of::<T>())
{
(listener)(
&DragMoveEvent {
event: event.clone(),
bounds: hitbox.bounds,
drag: PhantomData,
},
cx,
);
if phase == DispatchPhase::Capture {
if let Some(drag) = &cx.active_drag {
if drag.value.as_ref().type_id() == TypeId::of::<T>() {
(listener)(
&DragMoveEvent {
event: event.clone(),
bounds: hitbox.bounds,
drag: PhantomData,
dragged_item: Arc::clone(&drag.value),
},
cx,
);
}
}
}
}));
}
@@ -454,7 +461,7 @@ impl Interactivity {
"calling on_drag more than once on the same element is not supported"
);
self.drag_listener = Some((
Box::new(value),
Arc::new(value),
Box::new(move |value, offset, cx| {
constructor(value.downcast_ref().unwrap(), offset, cx).into()
}),
@@ -1292,7 +1299,7 @@ pub struct Interactivity {
pub(crate) drop_listeners: Vec<(TypeId, DropListener)>,
pub(crate) can_drop_predicate: Option<CanDropPredicate>,
pub(crate) click_listeners: Vec<ClickListener>,
pub(crate) drag_listener: Option<(Box<dyn Any>, DragListener)>,
pub(crate) drag_listener: Option<(Arc<dyn Any>, DragListener)>,
pub(crate) hover_listener: Option<Box<dyn Fn(&bool, &mut WindowContext)>>,
pub(crate) tooltip_builder: Option<TooltipBuilder>,
pub(crate) occlude_mouse: bool,
+17 -9
View File
@@ -385,20 +385,28 @@ impl LineLayoutCache {
let mut previous_frame = &mut *self.previous_frame.lock();
let mut current_frame = &mut *self.current_frame.write();
for key in &previous_frame.used_lines[range.start.lines_index..range.end.lines_index] {
if let Some((key, line)) = previous_frame.lines.remove_entry(key) {
current_frame.lines.insert(key, line);
if let Some(cached_keys) = previous_frame
.used_lines
.get(range.start.lines_index..range.end.lines_index)
{
for key in cached_keys {
if let Some((key, line)) = previous_frame.lines.remove_entry(key) {
current_frame.lines.insert(key, line);
}
current_frame.used_lines.push(key.clone());
}
current_frame.used_lines.push(key.clone());
}
for key in &previous_frame.used_wrapped_lines
[range.start.wrapped_lines_index..range.end.wrapped_lines_index]
if let Some(cached_keys) = previous_frame
.used_wrapped_lines
.get(range.start.wrapped_lines_index..range.end.wrapped_lines_index)
{
if let Some((key, line)) = previous_frame.wrapped_lines.remove_entry(key) {
current_frame.wrapped_lines.insert(key, line);
for key in cached_keys {
if let Some((key, line)) = previous_frame.wrapped_lines.remove_entry(key) {
current_frame.wrapped_lines.insert(key, line);
}
current_frame.used_wrapped_lines.push(key.clone());
}
current_frame.used_wrapped_lines.push(key.clone());
}
}
+13 -7
View File
@@ -1752,12 +1752,18 @@ impl<'a> WindowContext<'a> {
.iter_mut()
.map(|listener| listener.take()),
);
window.next_frame.accessed_element_states.extend(
window.rendered_frame.accessed_element_states[range.start.accessed_element_states_index
..range.end.accessed_element_states_index]
.iter()
.map(|(id, type_id)| (GlobalElementId(id.0.clone()), *type_id)),
);
if let Some(element_states) = window
.rendered_frame
.accessed_element_states
.get(range.start.accessed_element_states_index..range.end.accessed_element_states_index)
{
window.next_frame.accessed_element_states.extend(
element_states
.iter()
.map(|(id, type_id)| (GlobalElementId(id.0.clone()), *type_id)),
);
}
window
.text_system
.reuse_layouts(range.start.line_layout_index..range.end.line_layout_index);
@@ -3126,7 +3132,7 @@ impl<'a> WindowContext<'a> {
self.window.mouse_position = position;
if self.active_drag.is_none() {
self.active_drag = Some(AnyDrag {
value: Box::new(paths.clone()),
value: Arc::new(paths.clone()),
view: self.new_view(|_| paths).into(),
cursor_offset: position,
});