From 1f4e3d88c881e5402339a4a54750f06143f302ab Mon Sep 17 00:00:00 2001 From: raphCode <15750438+raphCode@users.noreply.github.com> Date: Fri, 29 Apr 2022 16:16:53 +0200 Subject: [PATCH] Fix crash on renaming a floating pane (#1323) (#1357) * Fix crash on renaming a floating pane (#1323) * Add rename tests for embedded and floating panes * docs(changelog): fix floating pane rename --- CHANGELOG.md | 1 + zellij-server/src/tab/mod.rs | 12 +++-- ...tegration_tests__rename_embedded_pane.snap | 25 +++++++++ ...tegration_tests__rename_floating_pane.snap | 25 +++++++++ .../src/tab/unit/tab_integration_tests.rs | 51 +++++++++++++++++++ 5 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__rename_embedded_pane.snap create mode 100644 zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__rename_floating_pane.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index eaf80f046..1d37449d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * fix: avoid panic in link_handler.rs (https://github.com/zellij-org/zellij/pull/1356) * Terminal compatibility: prevent wide chars from overflowing the title line (https://github.com/zellij-org/zellij/pull/1361) * Terminal compatibility: adjust saved cursor position on resize (https://github.com/zellij-org/zellij/pull/1362) +* fix: avoid panic on renaming a floating pane (https://github.com/zellij-org/zellij/pull/1357) * fix: change the way sessions are sorted (https://github.com/zellij-org/zellij/pull/1347) ## [0.28.1] - 2022-04-13 diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs index a32964dec..18eb99f33 100644 --- a/zellij-server/src/tab/mod.rs +++ b/zellij-server/src/tab/mod.rs @@ -1749,10 +1749,14 @@ impl Tab { pub fn update_active_pane_name(&mut self, buf: Vec, client_id: ClientId) { if let Some(active_terminal_id) = self.get_active_terminal_id(client_id) { - let active_terminal = self - .tiled_panes - .get_pane_mut(PaneId::Terminal(active_terminal_id)) - .unwrap(); + let active_terminal = if self.are_floating_panes_visible() { + self.floating_panes + .get_pane_mut(PaneId::Terminal(active_terminal_id)) + } else { + self.tiled_panes + .get_pane_mut(PaneId::Terminal(active_terminal_id)) + } + .unwrap(); // It only allows printable unicode, delete and backspace keys. let is_updatable = buf.iter().all(|u| matches!(u, 0x20..=0x7E | 0x08 | 0x7F)); diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__rename_embedded_pane.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__rename_embedded_pane.snap new file mode 100644 index 000000000..a71d4410e --- /dev/null +++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__rename_embedded_pane.snap @@ -0,0 +1,25 @@ +--- +source: zellij-server/src/tab/./unit/tab_integration_tests.rs +expression: snapshot +--- +00 (C): ┌ Renamed empedded pane ────────────────────────────────────────────────────────────────────────────────────────────────┐ +01 (C): │ │ +02 (C): │ │ +03 (C): │ │ +04 (C): │ I am an embedded pane │ +05 (C): │ │ +06 (C): │ │ +07 (C): │ │ +08 (C): │ │ +09 (C): │ │ +10 (C): │ │ +11 (C): │ │ +12 (C): │ │ +13 (C): │ │ +14 (C): │ │ +15 (C): │ │ +16 (C): │ │ +17 (C): │ │ +18 (C): │ │ +19 (C): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ + diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__rename_floating_pane.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__rename_floating_pane.snap new file mode 100644 index 000000000..cb73eb45c --- /dev/null +++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__rename_floating_pane.snap @@ -0,0 +1,25 @@ +--- +source: zellij-server/src/tab/./unit/tab_integration_tests.rs +expression: snapshot +--- +00 (C): ┌ Pane #1 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ +01 (C): │ │ +02 (C): │ │ +03 (C): │ │ +04 (C): │ │ +05 (C): │ ┌ Renamed floating pane ───────────────────────────────────┐ │ +06 (C): │ │ │ │ +07 (C): │ │ │ │ +08 (C): │ │ │ │ +09 (C): │ │ I am a floating pane │ │ +10 (C): │ │ │ │ +11 (C): │ │ │ │ +12 (C): │ │ │ │ +13 (C): │ │ │ │ +14 (C): │ └──────────────────────────────────────────────────────────┘ │ +15 (C): │ │ +16 (C): │ │ +17 (C): │ │ +18 (C): │ │ +19 (C): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ + diff --git a/zellij-server/src/tab/unit/tab_integration_tests.rs b/zellij-server/src/tab/unit/tab_integration_tests.rs index 352efadc7..fc35b444a 100644 --- a/zellij-server/src/tab/unit/tab_integration_tests.rs +++ b/zellij-server/src/tab/unit/tab_integration_tests.rs @@ -1096,6 +1096,57 @@ fn replacing_existing_wide_characters() { assert_snapshot!(snapshot); } +#[test] +fn rename_embedded_pane() { + let size = Size { + cols: 121, + rows: 20, + }; + let client_id = 1; + let mut tab = create_new_tab(size); + let mut output = Output::default(); + tab.handle_pty_bytes( + 1, + Vec::from("\n\n\n I am an embedded pane".as_bytes()), + ); + tab.update_active_pane_name("Renamed empedded pane".as_bytes().to_vec(), client_id); + tab.render(&mut output, None); + let snapshot = take_snapshot( + output.serialize().get(&client_id).unwrap(), + size.rows, + size.cols, + Palette::default(), + ); + assert_snapshot!(snapshot); +} + +#[test] +fn rename_floating_pane() { + let size = Size { + cols: 121, + rows: 20, + }; + let client_id = 1; + let mut tab = create_new_tab(size); + let new_pane_id = PaneId::Terminal(2); + let mut output = Output::default(); + tab.new_pane(new_pane_id, Some(client_id)); + tab.handle_pty_bytes( + 2, + Vec::from("\n\n\n I am a floating pane".as_bytes()), + ); + tab.toggle_pane_embed_or_floating(client_id); + tab.update_active_pane_name("Renamed floating pane".as_bytes().to_vec(), client_id); + tab.render(&mut output, None); + let snapshot = take_snapshot( + output.serialize().get(&client_id).unwrap(), + size.rows, + size.cols, + Palette::default(), + ); + assert_snapshot!(snapshot); +} + #[test] fn wide_characters_in_left_title_side() { // this test makes sure the title doesn't overflow when it has wide characters