ui/components/pane_actions.rs
1//! Reusable [`PaneGroup`](crate::PaneGroup) actions and their default
2//! keybindings — shared interaction logic that ships from `boltz-ui` itself
3//! (per the "shared logic -> shared crate" directive) so consumers mount a
4//! `PaneGroup` and get split/close/focus keyboard driving for free, with no
5//! per-app wiring.
6//!
7//! Keychord *values* are safe to ship as defaults: GPUI keybindings are
8//! overridable at the app layer, so a consumer wanting different keys
9//! rebinds locally (`cx.bind_keys([..])` after this call) with no republish
10//! required — only the default set lives upstream.
11
12use gpui::{App, KeyBinding, actions};
13
14actions!(
15 ui,
16 [
17 /// Splits the active pane, inserting the new pane to its right.
18 SplitRight,
19 /// Splits the active pane, inserting the new pane below it.
20 SplitDown,
21 /// Splits the active pane, inserting the new pane to its left.
22 SplitLeft,
23 /// Splits the active pane, inserting the new pane above it.
24 SplitUp,
25 /// Closes the active pane (no-op if it is the only pane left).
26 ClosePane,
27 /// Moves the active pane to its left neighbor, if any.
28 FocusLeft,
29 /// Moves the active pane to its right neighbor, if any.
30 FocusRight,
31 /// Moves the active pane to its neighbor above, if any.
32 FocusUp,
33 /// Moves the active pane to its neighbor below, if any.
34 FocusDown,
35 ]
36);
37
38/// Installs `boltz-ui`'s default `PaneGroup` keybindings, scoped to the
39/// `"PaneGroup"` key context that [`crate::PaneGroup`]'s `Render` impl sets
40/// on its root element:
41///
42/// - `super-d` -> [`SplitRight`]
43/// - `super-shift-d` -> [`SplitDown`]
44/// - `super-w` -> [`ClosePane`]
45/// - `super-alt-left`/`right`/`up`/`down` -> [`FocusLeft`]/[`FocusRight`]/[`FocusUp`]/[`FocusDown`]
46///
47/// `super` resolves to Cmd on macOS and the platform/Super key elsewhere.
48/// Call once during app startup; a consumer wanting different keys can call
49/// `cx.bind_keys([..])` afterwards to override any of these.
50///
51/// # Example
52/// ```ignore
53/// gpui::App::new().run(|cx| {
54/// ui::register_pane_keybindings(cx);
55/// // ...
56/// });
57/// ```
58pub fn register_pane_keybindings(cx: &mut App) {
59 cx.bind_keys([
60 KeyBinding::new("super-d", SplitRight, Some("PaneGroup")),
61 KeyBinding::new("super-shift-d", SplitDown, Some("PaneGroup")),
62 KeyBinding::new("super-w", ClosePane, Some("PaneGroup")),
63 KeyBinding::new("super-alt-left", FocusLeft, Some("PaneGroup")),
64 KeyBinding::new("super-alt-right", FocusRight, Some("PaneGroup")),
65 KeyBinding::new("super-alt-up", FocusUp, Some("PaneGroup")),
66 KeyBinding::new("super-alt-down", FocusDown, Some("PaneGroup")),
67 ]);
68}