diff options
Diffstat (limited to 'src/app/api')
| -rw-r--r-- | src/app/api/panes.rs | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/src/app/api/panes.rs b/src/app/api/panes.rs index 97fa0633..4cbdd661 100644 --- a/src/app/api/panes.rs +++ b/src/app/api/panes.rs @@ -3,11 +3,12 @@ use bytes::Bytes; use crate::api::schema::{ EventData, EventEnvelope, EventKind, PaneClearAgentAuthorityParams, PaneCurrentParams, PaneDirection, PaneEdgesParams, PaneEdgesResult, PaneFocusDirectionParams, - PaneFocusDirectionReason, PaneFocusDirectionResult, PaneInfo, PaneLayoutPane, PaneLayoutParams, - PaneLayoutRect, PaneLayoutSnapshot, PaneLayoutSplit, PaneListParams, PaneMoveDestination, - PaneMoveParams, PaneMoveReason, PaneMoveResult, PaneNeighborParams, PaneNeighborResult, - PaneProcessInfo, PaneProcessInfoParams, PaneProcessInfoProcess, PaneReadParams, PaneReadResult, - PaneReleaseAgentParams, PaneRenameParams, PaneReportAgentParams, PaneReportAgentSessionParams, + PaneFocusDirectionReason, PaneFocusDirectionResult, PaneInfo, PaneInputSetParams, + PaneLayoutPane, PaneLayoutParams, PaneLayoutRect, PaneLayoutSnapshot, PaneLayoutSplit, + PaneListParams, PaneMoveDestination, PaneMoveParams, PaneMoveReason, PaneMoveResult, + PaneNeighborParams, PaneNeighborResult, PaneProcessInfo, PaneProcessInfoParams, + PaneProcessInfoProcess, PaneReadParams, PaneReadResult, PaneReleaseAgentParams, + PaneRenameParams, PaneReportAgentParams, PaneReportAgentSessionParams, PaneReportMetadataParams, PaneResizeParams, PaneResizeReason, PaneResizeResult, PaneSendInputParams, PaneSendKeysParams, PaneSendTextParams, PaneSplitParams, PaneSwapParams, PaneSwapReason, PaneSwapResult, PaneTarget, PaneZoomMode, PaneZoomParams, PaneZoomReason, @@ -101,6 +102,12 @@ impl App { Some(Err(err)) => return encode_error(id, "pane_split_failed", err.to_string()), None => return encode_error(id, "pane_not_found", "pane not found"), }; + if let Some(pane) = self.state.workspaces[ws_idx].pane_state_mut(new_pane.pane_id) { + pane.right_click_passthrough = matches!( + params.right_click, + crate::api::schema::PaneRightClickTarget::Pane + ); + } if params.focus { self.state.switch_workspace_tab(ws_idx, target_tab_idx); self.state @@ -1130,6 +1137,29 @@ impl App { ) } + pub(super) fn handle_pane_input_set( + &mut self, + id: String, + params: PaneInputSetParams, + ) -> String { + let Some((ws_idx, pane_id)) = self.parse_pane_id(¶ms.pane_id) else { + return pane_not_found(id, ¶ms.pane_id); + }; + let Some(pane) = self + .state + .workspaces + .get_mut(ws_idx) + .and_then(|workspace| workspace.pane_state_mut(pane_id)) + else { + return pane_not_found(id, ¶ms.pane_id); + }; + pane.right_click_passthrough = matches!( + params.right_click, + crate::api::schema::PaneRightClickTarget::Pane + ); + encode_success(id, ResponseResult::Ok {}) + } + pub(super) fn handle_pane_rename(&mut self, id: String, params: PaneRenameParams) -> String { let Some((ws_idx, pane_id)) = self.parse_pane_id(¶ms.pane_id) else { return pane_not_found(id, ¶ms.pane_id); @@ -1893,6 +1923,36 @@ mod tests { (app, public_pane_id) } + #[test] + fn pane_input_set_changes_only_the_target_pane() { + let (mut app, public_pane_id) = app_with_test_workspace(); + let target = app.state.workspaces[0].tabs[0].root_pane; + let other = app.state.workspaces[0].test_split(ratatui::layout::Direction::Horizontal); + + let response = app.handle_pane_input_set( + "req".into(), + PaneInputSetParams { + pane_id: public_pane_id, + right_click: crate::api::schema::PaneRightClickTarget::Pane, + }, + ); + + let response: SuccessResponse = serde_json::from_str(&response).unwrap(); + assert!(matches!(response.result, ResponseResult::Ok {})); + assert!( + app.state.workspaces[0] + .pane_state(target) + .unwrap() + .right_click_passthrough + ); + assert!( + !app.state.workspaces[0] + .pane_state(other) + .unwrap() + .right_click_passthrough + ); + } + fn app_with_send_key_runtime( capacity: usize, ) -> (App, String, tokio::sync::mpsc::Receiver<bytes::Bytes>) { |
