summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/panes/floating_panes/mod.rs
diff options
context:
space:
mode:
authorCosmin Popescu <cosminadrianpopescu@gmail.com>2022-06-06 09:20:07 +0200
committerGitHub <noreply@github.com>2022-06-06 09:20:07 +0200
commite1fcf3a6dbc7a65a341127fab2fca7b4fb2d081b (patch)
treeec1061b57347348f081d64c532f7fc12ff21c4dd /zellij-server/src/panes/floating_panes/mod.rs
parent58cc8fb2e1a091dca72fdbaf9150b200e130fa73 (diff)
feat(scroll): edit scrollback with default editor (#1456)
* initial commit for opening the current buffer in an editor * fix(editor): take hidden panes into consideration when manipulating tiled grid * when closing an edit buffer, take the geometry of the replaced buffer from the closed buffer * if the floating panels are displayed, don't add to hidden panels the current buffer * strategy changing - put the panels inside a suppressed_panels HashMap instead of hidden_panels * Revert "strategy changing - put the panels inside a suppressed_panels HashMap instead of hidden_panels" This reverts commit c52a203a20cf4c87c147be8b9c193ed6458c1038. * remove the floating panes by moving them to the tiled_panes in hidden_panels * feat(edit): open editor to correct line and don't crash when none is set * formatting * feat(edit): use suppressed panes * style(fmt): rustfmt and logs * style(fmt): clean up unused code * test(editor): integration test for suppressing/closing suppressed pane * test(e2e): editor e2e test * style(fmt): rustfmt * feat(edit): update ui and setup * style(fmt): rustfmt * feat(config): allow configuring scrollback_editor explicitly * style(fmt): rustfmt * chore(repo): build after merging Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to 'zellij-server/src/panes/floating_panes/mod.rs')
-rw-r--r--zellij-server/src/panes/floating_panes/mod.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/zellij-server/src/panes/floating_panes/mod.rs b/zellij-server/src/panes/floating_panes/mod.rs
index e4925c365..f8bd46bc3 100644
--- a/zellij-server/src/panes/floating_panes/mod.rs
+++ b/zellij-server/src/panes/floating_panes/mod.rs
@@ -101,6 +101,49 @@ impl FloatingPanes {
self.panes.insert(pane_id, pane);
self.z_indices.push(pane_id);
}
+ pub fn replace_active_pane(
+ &mut self,
+ pane: Box<dyn Pane>,
+ client_id: ClientId,
+ ) -> Option<Box<dyn Pane>> {
+ self.active_panes
+ .get(&client_id)
+ .copied()
+ .and_then(|active_pane_id| self.replace_pane(active_pane_id, pane))
+ }
+ pub fn replace_pane(
+ &mut self,
+ pane_id: PaneId,
+ mut with_pane: Box<dyn Pane>,
+ ) -> Option<Box<dyn Pane>> {
+ let with_pane_id = with_pane.pid();
+ with_pane.set_content_offset(Offset::frame(1));
+ let removed_pane = self.panes.remove(&pane_id).map(|removed_pane| {
+ let removed_pane_id = removed_pane.pid();
+ let with_pane_id = with_pane.pid();
+ let removed_pane_geom = removed_pane.current_geom();
+ with_pane.set_geom(removed_pane_geom);
+ self.panes.insert(with_pane_id, with_pane);
+ let z_index = self
+ .z_indices
+ .iter()
+ .position(|pane_id| pane_id == &removed_pane_id)
+ .unwrap();
+ self.z_indices.remove(z_index);
+ self.z_indices.insert(z_index, with_pane_id);
+ removed_pane
+ });
+
+ // update the desired_pane_positions to relate to the new pane
+ if let Some(desired_pane_position) = self.desired_pane_positions.remove(&pane_id) {
+ self.desired_pane_positions
+ .insert(with_pane_id, desired_pane_position);
+ }
+
+ // move clients from the previously active pane to the new pane we just inserted
+ self.move_clients_between_panes(pane_id, with_pane_id);
+ removed_pane
+ }
pub fn remove_pane(&mut self, pane_id: PaneId) -> Option<Box<dyn Pane>> {
self.z_indices.retain(|p_id| *p_id != pane_id);
self.desired_pane_positions.remove(&pane_id);
@@ -241,6 +284,11 @@ impl FloatingPanes {
floating_pane_grid.resize(new_screen_size);
self.set_force_render();
}
+ pub fn resize_pty_all_panes(&mut self, os_api: &mut Box<dyn ServerOsApi>) {
+ for pane in self.panes.values_mut() {
+ resize_pty!(pane, os_api);
+ }
+ }
pub fn resize_active_pane_left(
&mut self,
client_id: ClientId,
@@ -875,4 +923,16 @@ impl FloatingPanes {
pub fn get_panes(&self) -> impl Iterator<Item = (&PaneId, &Box<dyn Pane>)> {
self.panes.iter()
}
+ fn move_clients_between_panes(&mut self, from_pane_id: PaneId, to_pane_id: PaneId) {
+ let clients_in_pane: Vec<ClientId> = self
+ .active_panes
+ .iter()
+ .filter(|(_cid, pid)| **pid == from_pane_id)
+ .map(|(cid, _pid)| *cid)
+ .collect();
+ for client_id in clients_in_pane {
+ self.active_panes.remove(&client_id);
+ self.active_panes.insert(client_id, to_pane_id);
+ }
+ }
}