aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/kdl
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-12-16 16:03:20 +0100
committerGitHub <noreply@github.com>2024-12-16 16:03:20 +0100
commitdd291e2a1f9b4ee3eb1a947e1501a54b10663ea7 (patch)
tree0ae41e8175d2a3fd260b3c510a30502f6386ac7f /zellij-utils/src/kdl
parentdocs(changelog): multiplayer cursor fix (diff)
downloadsl0ppij-dd291e2a1f9b4ee3eb1a947e1501a54b10663ea7.tar.gz
sl0ppij-dd291e2a1f9b4ee3eb1a947e1501a54b10663ea7.tar.xz
sl0ppij-dd291e2a1f9b4ee3eb1a947e1501a54b10663ea7.zip
feat(ux): pin floating panes (#3876)
* working * ui indication * add keybinding * add to plugin panes * fix with multiple cursors * toggle with the mouse * fix e2e tests and add new one * some cleanups * add to layouts * make mouse click more lenient * allow setting a new floating pane as pinned * make toggle work throughthe command line * add to plugin api * get tests to pass * style(fmt): rustfmt
Diffstat (limited to 'zellij-utils/src/kdl')
-rw-r--r--zellij-utils/src/kdl/kdl_layout_parser.rs23
-rw-r--r--zellij-utils/src/kdl/mod.rs6
-rw-r--r--zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap3
-rw-r--r--zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap3
4 files changed, 29 insertions, 6 deletions
diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs
index 81e97a7e..c38c0146 100644
--- a/zellij-utils/src/kdl/kdl_layout_parser.rs
+++ b/zellij-utils/src/kdl/kdl_layout_parser.rs
@@ -122,6 +122,7 @@ impl<'a> KdlLayoutParser<'a> {
|| property_name == "y"
|| property_name == "width"
|| property_name == "height"
+ || property_name == "pinned"
|| property_name == "contents_file"
}
fn is_a_valid_tab_property(&self, property_name: &str) -> bool {
@@ -596,6 +597,7 @@ impl<'a> KdlLayoutParser<'a> {
let width = self.parse_percent_or_fixed(kdl_node, "width", false)?;
let x = self.parse_percent_or_fixed(kdl_node, "x", true)?;
let y = self.parse_percent_or_fixed(kdl_node, "y", true)?;
+ let pinned = kdl_get_bool_property_or_child_value_with_error!(kdl_node, "pinned");
let run = self.parse_command_plugin_or_edit_block(kdl_node)?;
let focus = kdl_get_bool_property_or_child_value_with_error!(kdl_node, "focus");
let name = kdl_get_string_property_or_child_value_with_error!(kdl_node, "name")
@@ -619,6 +621,7 @@ impl<'a> KdlLayoutParser<'a> {
y,
run,
focus,
+ pinned,
pane_initial_contents,
..Default::default()
})
@@ -845,7 +848,7 @@ impl<'a> KdlLayoutParser<'a> {
let width = self.parse_percent_or_fixed(kdl_node, "width", false)?;
let x = self.parse_percent_or_fixed(kdl_node, "x", true)?;
let y = self.parse_percent_or_fixed(kdl_node, "y", true)?;
- // let mut floating_pane = FloatingPaneLayout::from(&pane_template);
+ let pinned = kdl_get_bool_property_or_child_value_with_error!(kdl_node, "pinned");
if let Some(height) = height {
pane_template.height = Some(height);
}
@@ -858,6 +861,9 @@ impl<'a> KdlLayoutParser<'a> {
if let Some(x) = x {
pane_template.x = Some(x);
}
+ if let Some(pinned) = pinned {
+ pane_template.pinned = Some(pinned);
+ }
Ok(pane_template)
},
PaneOrFloatingPane::Either(mut pane_template) => {
@@ -896,6 +902,7 @@ impl<'a> KdlLayoutParser<'a> {
let width = self.parse_percent_or_fixed(kdl_node, "width", false)?;
let x = self.parse_percent_or_fixed(kdl_node, "x", true)?;
let y = self.parse_percent_or_fixed(kdl_node, "y", true)?;
+ let pinned = kdl_get_bool_property_or_child_value_with_error!(kdl_node, "pinned");
let mut floating_pane = FloatingPaneLayout::from(&pane_template);
if let Some(height) = height {
floating_pane.height = Some(height);
@@ -909,6 +916,9 @@ impl<'a> KdlLayoutParser<'a> {
if let Some(x) = x {
floating_pane.x = Some(x);
}
+ if let Some(pinned) = pinned {
+ floating_pane.pinned = Some(pinned);
+ }
Ok(floating_pane)
},
}
@@ -948,6 +958,7 @@ impl<'a> KdlLayoutParser<'a> {
let width = self.parse_percent_or_fixed(kdl_node, "width", false)?;
let x = self.parse_percent_or_fixed(kdl_node, "x", true)?;
let y = self.parse_percent_or_fixed(kdl_node, "y", true)?;
+ let pinned = kdl_get_string_property_or_child_value_with_error!(kdl_node, "pinned");
let has_pane_properties = borderless.is_some()
|| split_size.is_some()
@@ -956,7 +967,7 @@ impl<'a> KdlLayoutParser<'a> {
|| is_expanded_in_stack.is_some()
|| has_children_nodes;
let has_floating_pane_properties =
- height.is_some() || width.is_some() || x.is_some() || y.is_some();
+ height.is_some() || width.is_some() || x.is_some() || y.is_some() || pinned.is_some();
if has_pane_properties || has_floating_pane_properties {
Ok(false)
} else {
@@ -985,6 +996,7 @@ impl<'a> KdlLayoutParser<'a> {
let width = self.parse_percent_or_fixed(kdl_node, "width", false)?;
let x = self.parse_percent_or_fixed(kdl_node, "x", true)?;
let y = self.parse_percent_or_fixed(kdl_node, "y", true)?;
+ let pinned = kdl_get_bool_property_or_child_value_with_error!(kdl_node, "pinned");
let has_pane_properties = borderless.is_some()
|| split_size.is_some()
@@ -993,7 +1005,7 @@ impl<'a> KdlLayoutParser<'a> {
|| is_expanded_in_stack.is_some()
|| has_children_nodes;
let has_floating_pane_properties =
- height.is_some() || width.is_some() || x.is_some() || y.is_some();
+ height.is_some() || width.is_some() || x.is_some() || y.is_some() || pinned.is_some();
if has_pane_properties && has_floating_pane_properties {
let mut pane_properties = vec![];
@@ -1028,6 +1040,9 @@ impl<'a> KdlLayoutParser<'a> {
if y.is_some() {
floating_pane_properties.push("y");
}
+ if pinned.is_some() {
+ floating_pane_properties.push("pinned");
+ }
Err(ConfigError::new_layout_kdl_error(
format!(
"A pane_template cannot have both pane ({}) and floating pane ({}) properties",
@@ -1079,6 +1094,7 @@ impl<'a> KdlLayoutParser<'a> {
let width = self.parse_percent_or_fixed(kdl_node, "width", false)?;
let x = self.parse_percent_or_fixed(kdl_node, "x", true)?;
let y = self.parse_percent_or_fixed(kdl_node, "y", true)?;
+ let pinned = kdl_get_bool_property_or_child_value_with_error!(kdl_node, "pinned");
self.pane_templates.insert(
template_name,
(
@@ -1089,6 +1105,7 @@ impl<'a> KdlLayoutParser<'a> {
width,
x,
y,
+ pinned,
..Default::default()
}),
kdl_node.clone(),
diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs
index e3726173..37f36fd8 100644
--- a/zellij-utils/src/kdl/mod.rs
+++ b/zellij-utils/src/kdl/mod.rs
@@ -1101,6 +1101,7 @@ impl Action {
}
Some(node)
},
+ Action::TogglePanePinned => Some(KdlNode::new("TogglePanePinned")),
_ => None,
}
}
@@ -1537,11 +1538,13 @@ impl TryFrom<(&KdlNode, &Options)> for Action {
let height = command_metadata
.and_then(|c_m| kdl_child_string_value_for_entry(c_m, "height"))
.map(|s| s.to_owned());
+ let pinned =
+ command_metadata.and_then(|c_m| kdl_child_bool_value_for_entry(c_m, "pinned"));
if floating {
Ok(Action::NewFloatingPane(
Some(run_command_action),
name,
- FloatingPaneCoordinates::new(x, y, width, height),
+ FloatingPaneCoordinates::new(x, y, width, height, pinned),
))
} else if in_place {
Ok(Action::NewInPlacePane(Some(run_command_action), name))
@@ -1758,6 +1761,7 @@ impl TryFrom<(&KdlNode, &Options)> for Action {
plugin_id,
})
},
+ "TogglePanePinned" => Ok(Action::TogglePanePinned),
_ => Err(ConfigError::new_kdl_error(
format!("Unsupported action: {}", action_name).into(),
kdl_action.span().offset(),
diff --git a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap
index 6a709ef9..bcd3ac0e 100644
--- a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap
+++ b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap
@@ -1,6 +1,6 @@
---
source: zellij-utils/src/kdl/mod.rs
-assertion_line: 5535
+assertion_line: 5551
expression: fake_config_stringified
---
keybinds clear-defaults=true {
@@ -17,6 +17,7 @@ keybinds clear-defaults=true {
bind "e" { TogglePaneEmbedOrFloating; SwitchToMode "normal"; }
bind "f" { ToggleFocusFullscreen; SwitchToMode "normal"; }
bind "h" { MoveFocus "left"; }
+ bind "i" { TogglePanePinned; SwitchToMode "normal"; }
bind "j" { MoveFocus "down"; }
bind "k" { MoveFocus "up"; }
bind "l" { MoveFocus "right"; }
diff --git a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap
index b4bbbefe..f31c73d3 100644
--- a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap
+++ b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap
@@ -1,6 +1,6 @@
---
source: zellij-utils/src/kdl/mod.rs
-assertion_line: 5547
+assertion_line: 5563
expression: fake_config_stringified
---
keybinds clear-defaults=true {
@@ -17,6 +17,7 @@ keybinds clear-defaults=true {
bind "e" { TogglePaneEmbedOrFloating; SwitchToMode "normal"; }
bind "f" { ToggleFocusFullscreen; SwitchToMode "normal"; }
bind "h" { MoveFocus "left"; }
+ bind "i" { TogglePanePinned; SwitchToMode "normal"; }
bind "j" { MoveFocus "down"; }
bind "k" { MoveFocus "up"; }
bind "l" { MoveFocus "right"; }