aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/input
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2026-01-15 14:10:59 +0100
committerGitHub <noreply@github.com>2026-01-15 14:10:59 +0100
commit005769cfa58b65cc6b2d6ce273ad367bf802bfb0 (patch)
tree1912882005cc78bd27d53414ab672b6a13ecd4c8 /zellij-utils/src/input
parentfix: properly quit welcome screen when switching sessions (#4605) (diff)
downloadsl0ppij-005769cfa58b65cc6b2d6ce273ad367bf802bfb0.tar.gz
sl0ppij-005769cfa58b65cc6b2d6ce273ad367bf802bfb0.tar.xz
sl0ppij-005769cfa58b65cc6b2d6ce273ad367bf802bfb0.zip
Fix: allow 0% coordinate specification for floating panes (#4609)
* fix: allow 0% when specifying x/y coordinates but not when specifying width/height * rustfmt * add pr
Diffstat (limited to 'zellij-utils/src/input')
-rw-r--r--zellij-utils/src/input/layout.rs6
-rw-r--r--zellij-utils/src/input/unit/layout_test.rs117
2 files changed, 120 insertions, 3 deletions
diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs
index ae7d85a1..a7b2ebc6 100644
--- a/zellij-utils/src/input/layout.rs
+++ b/zellij-utils/src/input/layout.rs
@@ -715,7 +715,7 @@ pub struct TabLayoutInfo {
pub swap_floating_layouts: Option<Vec<SwapFloatingLayout>>,
}
-#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
+#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum PercentOrFixed {
Percent(usize), // 1 to 100
Fixed(usize), // An absolute number of columns or rows
@@ -745,10 +745,10 @@ impl PercentOrFixed {
},
}
}
- pub fn to_fixed(&self, full_size: usize) -> usize {
+ pub fn to_fixed(&self, whole: usize) -> usize {
match self {
PercentOrFixed::Percent(percent) => {
- ((*percent as f64 / 100.0) * full_size as f64).floor() as usize
+ ((*percent as f64 / 100.0) * whole as f64).floor() as usize
},
PercentOrFixed::Fixed(fixed) => *fixed,
}
diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs
index 292909e5..8a86247f 100644
--- a/zellij-utils/src/input/unit/layout_test.rs
+++ b/zellij-utils/src/input/unit/layout_test.rs
@@ -2361,3 +2361,120 @@ fn layout_node_with_name_and_only_floating_panes() {
assert_eq!(layout.tabs.len(), 1);
assert_eq!(layout.tabs[0].0, Some("floating-only".to_string()));
}
+
+#[test]
+fn floating_pane_coordinates_allows_zero_percent_for_x_y() {
+ use crate::data::FloatingPaneCoordinates;
+ use crate::input::layout::PercentOrFixed;
+
+ let coords = FloatingPaneCoordinates::new(
+ Some("0%".to_string()),
+ Some("0%".to_string()),
+ Some("50%".to_string()),
+ Some("50%".to_string()),
+ None,
+ );
+
+ assert!(coords.is_some());
+ let coords = coords.unwrap();
+ assert_eq!(coords.x, Some(PercentOrFixed::Percent(0)));
+ assert_eq!(coords.y, Some(PercentOrFixed::Percent(0)));
+ assert_eq!(coords.width, Some(PercentOrFixed::Percent(50)));
+ assert_eq!(coords.height, Some(PercentOrFixed::Percent(50)));
+}
+
+#[test]
+fn floating_pane_coordinates_rejects_zero_percent_for_width() {
+ use crate::data::FloatingPaneCoordinates;
+ use crate::input::layout::PercentOrFixed;
+
+ let coords = FloatingPaneCoordinates::new(
+ Some("10%".to_string()),
+ Some("10%".to_string()),
+ Some("0%".to_string()),
+ Some("50%".to_string()),
+ None,
+ );
+
+ // Should have coords but width will be None due to rejection
+ assert!(coords.is_some());
+ let coords = coords.unwrap();
+ assert!(coords.width.is_none());
+ assert_eq!(coords.height, Some(PercentOrFixed::Percent(50)));
+}
+
+#[test]
+fn floating_pane_coordinates_rejects_zero_percent_for_height() {
+ use crate::data::FloatingPaneCoordinates;
+ use crate::input::layout::PercentOrFixed;
+
+ let coords = FloatingPaneCoordinates::new(
+ Some("10%".to_string()),
+ Some("10%".to_string()),
+ Some("50%".to_string()),
+ Some("0%".to_string()),
+ None,
+ );
+
+ // Should have coords but height will be None due to rejection
+ assert!(coords.is_some());
+ let coords = coords.unwrap();
+ assert_eq!(coords.width, Some(PercentOrFixed::Percent(50)));
+ assert!(coords.height.is_none());
+}
+
+#[test]
+fn floating_pane_coordinates_static_zero_works() {
+ use crate::data::FloatingPaneCoordinates;
+ use crate::input::layout::PercentOrFixed;
+
+ let coords = FloatingPaneCoordinates::new(
+ Some("0".to_string()),
+ Some("0".to_string()),
+ Some("100".to_string()),
+ Some("100".to_string()),
+ None,
+ );
+
+ assert!(coords.is_some());
+ let coords = coords.unwrap();
+ assert_eq!(coords.x, Some(PercentOrFixed::Fixed(0)));
+ assert_eq!(coords.y, Some(PercentOrFixed::Fixed(0)));
+ assert_eq!(coords.width, Some(PercentOrFixed::Fixed(100)));
+ assert_eq!(coords.height, Some(PercentOrFixed::Fixed(100)));
+}
+
+#[test]
+fn floating_pane_coordinates_one_percent_works() {
+ use crate::data::FloatingPaneCoordinates;
+ use crate::input::layout::PercentOrFixed;
+
+ let coords = FloatingPaneCoordinates::new(
+ Some("1%".to_string()),
+ Some("1%".to_string()),
+ Some("50%".to_string()),
+ Some("50%".to_string()),
+ None,
+ );
+
+ assert!(coords.is_some());
+ let coords = coords.unwrap();
+ assert_eq!(coords.x, Some(PercentOrFixed::Percent(1)));
+ assert_eq!(coords.y, Some(PercentOrFixed::Percent(1)));
+ assert_eq!(coords.width, Some(PercentOrFixed::Percent(50)));
+ assert_eq!(coords.height, Some(PercentOrFixed::Percent(50)));
+}
+
+#[test]
+fn tiled_pane_still_rejects_zero_percent() {
+ use crate::input::layout::SplitSize;
+ use std::str::FromStr;
+
+ // Verify SplitSize::from_str still rejects 0%
+ let result = SplitSize::from_str("0%");
+ assert!(result.is_err());
+
+ // But 1% should work
+ let result = SplitSize::from_str("1%");
+ assert!(result.is_ok());
+}