Skip to content

Commit

Permalink
feat(ui): break pane to new tab and move panes between tabs (#2664)
Browse files Browse the repository at this point in the history
* prototype

* some tests

* break out floating pane

* break out plugin panes

* add keybind and fix some minor issues

* remove cli

* move pane to left/right tab

* update ui

* adjust ui

* style(fmt): rustfmt

* style(comment): remove commented code

* update snapshots
  • Loading branch information
imsnif authored Aug 2, 2023
1 parent 8fb9039 commit 192e6fd
Show file tree
Hide file tree
Showing 108 changed files with 2,200 additions and 157 deletions.
7 changes: 6 additions & 1 deletion default-plugins/status-bar/src/second_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ fn get_keys_and_hints(mi: &ModeInfo) -> Vec<(String, String, Vec<Key>)> {
(s("Rename"), s("Rename"),
action_key(&km, &[A::SwitchToMode(IM::RenameTab), A::TabNameInput(vec![0])])),
(s("Sync"), s("Sync"), action_key(&km, &[A::ToggleActiveSyncTab, TO_NORMAL])),
(s("Toggle"), s("Toggle"), action_key(&km, &[A::ToggleTab])),
(s("Break pane to new tab"), s("Break"), action_key(&km, &[A::BreakPane, TO_NORMAL])),
(s("Break pane to next/prev tab"), s("Break next/prev"),
action_key_group(&km, &[
&[A::BreakPaneLeft, TO_NORMAL],
&[A::BreakPaneRight, TO_NORMAL]
])),
(s("Select pane"), s("Select"), to_normal_key),
]} else if mi.mode == IM::Resize { vec![
(s("Increase/Decrease size"), s("Increase/Decrease"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ expression: second_runner_snapshot
│ ││ │
└──────────────────────────────────────────────────────────┘└──────────────────────────────────────────────────────────┘
Ctrl + <g> LOCK  <p> PANE  <t> TAB  <n> RESIZE  <h> MOVE  <s> SEARCH  <o> SESSION  <q> QUIT 
<n> New / <←→> Change focus / <x> Close / <r> Rename / <s> Sync / <TAB> Toggle / <ENTER> Select pane
<n> New / <←→> Move / <x> Close / <r> Rename / <s> Sync / <b> Break / <[]> Break next/prev / <ENTER> Select
14 changes: 14 additions & 0 deletions zellij-server/src/panes/floating_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,4 +898,18 @@ impl FloatingPanes {
}
pane_infos
}
pub fn set_geom_for_pane_with_run(&mut self, run: Option<Run>, geom: PaneGeom) {
match self
.panes
.iter_mut()
.find(|(_, p)| p.invoked_with() == &run)
{
Some((_, pane)) => {
pane.set_geom(geom);
},
None => {
log::error!("Failed to find pane with run: {:?}", run);
},
}
}
}
48 changes: 43 additions & 5 deletions zellij-server/src/panes/tiled_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,13 @@ impl TiledPanes {
let has_room_for_new_pane = pane_grid
.find_room_for_new_pane(cursor_height_width_ratio)
.is_some();
has_room_for_new_pane || pane_grid.has_room_for_new_stacked_pane()
has_room_for_new_pane || pane_grid.has_room_for_new_stacked_pane() || self.panes.is_empty()
}
fn add_pane(&mut self, pane_id: PaneId, mut pane: Box<dyn Pane>, should_relayout: bool) {
if self.panes.is_empty() {
self.panes.insert(pane_id, pane);
return;
}
let cursor_height_width_ratio = self.cursor_height_width_ratio();
let mut pane_grid = TiledPaneGrid::new(
&mut self.panes,
Expand Down Expand Up @@ -250,6 +254,19 @@ impl TiledPanes {
})
.collect()
}
pub fn non_selectable_pane_geoms_inside_viewport(&self) -> Vec<Viewport> {
self.panes
.values()
.filter_map(|p| {
let geom = p.position_and_size();
if !p.selectable() && is_inside_viewport(&self.viewport.borrow(), p) {
Some(geom.into())
} else {
None
}
})
.collect()
}
pub fn first_selectable_pane_id(&self) -> Option<PaneId> {
self.panes
.iter()
Expand Down Expand Up @@ -587,8 +604,6 @@ impl TiledPanes {
pub fn focused_pane_id(&self, client_id: ClientId) -> Option<PaneId> {
self.active_panes.get(&client_id).copied()
}
// FIXME: Really not a fan of allowing this... Someone with more energy
// than me should clean this up someday...
#[allow(clippy::borrowed_box)]
pub fn get_pane(&self, pane_id: PaneId) -> Option<&Box<dyn Pane>> {
self.panes.get(&pane_id)
Expand Down Expand Up @@ -735,6 +750,29 @@ impl TiledPanes {
pub fn get_panes(&self) -> impl Iterator<Item = (&PaneId, &Box<dyn Pane>)> {
self.panes.iter()
}
pub fn set_geom_for_pane_with_run(
&mut self,
run: Option<Run>,
geom: PaneGeom,
borderless: bool,
) {
match self
.panes
.iter_mut()
.find(|(_, p)| p.invoked_with() == &run)
{
Some((_, pane)) => {
pane.set_geom(geom);
pane.set_borderless(borderless);
if self.draw_pane_frames {
pane.set_content_offset(Offset::frame(1));
}
},
None => {
log::error!("Failed to find pane with run: {:?}", run);
},
}
}
pub fn resize(&mut self, new_screen_size: Size) {
// this is blocked out to appease the borrow checker
{
Expand Down Expand Up @@ -1501,11 +1539,11 @@ impl TiledPanes {
self.set_pane_frames(self.draw_pane_frames); // recalculate pane frames and update size
closed_pane
} else {
self.panes.remove(&pane_id);
let closed_pane = self.panes.remove(&pane_id);
// this is a bit of a roundabout way to say: this is the last pane and so the tab
// should be destroyed
self.active_panes.clear(&mut self.panes);
None
closed_pane
}
}
pub fn hold_pane(
Expand Down
1 change: 1 addition & 0 deletions zellij-server/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ pub(crate) fn plugin_thread_main(
};
let mut extracted_floating_plugins: Vec<Option<Run>> = floating_panes_layout
.iter()
.filter(|f| !f.already_running)
.map(|f| f.run.clone())
.collect();
extracted_run_instructions.append(&mut extracted_floating_plugins);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: zellij-server/src/plugins/./unit/plugin_tests.rs
assertion_line: 521
assertion_line: 735
expression: "format!(\"{:#?}\", second_new_tab_event)"
---
Some(
Expand All @@ -24,6 +24,7 @@ Some(
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
run_instructions_to_ignore: [],
},
TiledPaneLayout {
children_split_direction: Horizontal,
Expand All @@ -37,6 +38,7 @@ Some(
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
run_instructions_to_ignore: [],
},
],
split_size: None,
Expand All @@ -47,6 +49,7 @@ Some(
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
run_instructions_to_ignore: [],
},
),
[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: zellij-server/src/plugins/./unit/plugin_tests.rs
assertion_line: 520
assertion_line: 734
expression: "format!(\"{:#?}\", first_new_tab_event)"
---
Some(
Expand All @@ -24,6 +24,7 @@ Some(
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
run_instructions_to_ignore: [],
},
TiledPaneLayout {
children_split_direction: Horizontal,
Expand All @@ -37,6 +38,7 @@ Some(
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
run_instructions_to_ignore: [],
},
],
split_size: None,
Expand All @@ -47,6 +49,7 @@ Some(
children_are_stacked: false,
is_expanded_in_stack: false,
exclude_from_sync: None,
run_instructions_to_ignore: [],
},
),
[],
Expand Down
6 changes: 4 additions & 2 deletions zellij-server/src/pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,10 @@ impl Pty {
default_shell.unwrap_or_else(|| self.get_default_terminal(cwd, None));
self.fill_cwd(&mut default_shell, client_id);
let extracted_run_instructions = layout.extract_run_instructions();
let extracted_floating_run_instructions =
floating_panes_layout.iter().map(|f| f.run.clone());
let extracted_floating_run_instructions = floating_panes_layout
.iter()
.filter(|f| !f.already_running)
.map(|f| f.run.clone());
let mut new_pane_pids: Vec<(u32, bool, Option<RunCommand>, Result<RawFd>)> = vec![]; // (terminal_id,
// starts_held,
// run_command,
Expand Down
19 changes: 19 additions & 0 deletions zellij-server/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,25 @@ pub(crate) fn route_action(
))
.with_context(err_context)?;
},
Action::BreakPane => {
senders
.send_to_screen(ScreenInstruction::BreakPane(
default_layout.clone(),
default_shell.clone(),
client_id,
))
.with_context(err_context)?;
},
Action::BreakPaneRight => {
senders
.send_to_screen(ScreenInstruction::BreakPaneRight(client_id))
.with_context(err_context)?;
},
Action::BreakPaneLeft => {
senders
.send_to_screen(ScreenInstruction::BreakPaneLeft(client_id))
.with_context(err_context)?;
},
}
Ok(should_break)
}
Expand Down
Loading

0 comments on commit 192e6fd

Please sign in to comment.