Skip to content

Commit

Permalink
PaneSelect: MoveToNewTab, MoveToNewWindow and show_pane_ids
Browse files Browse the repository at this point in the history
refs: #4147
  • Loading branch information
wez committed Aug 25, 2023
1 parent c91e124 commit a9c7d28
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config/src/keyassignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ impl Default for ClipboardPasteSource {
pub enum PaneSelectMode {
Activate,
SwapWithActive,
MoveToNewTab,
MoveToNewWindow,
}

impl Default for PaneSelectMode {
Expand All @@ -349,6 +351,9 @@ pub struct PaneSelectArguments {

#[dynamic(default)]
pub mode: PaneSelectMode,

#[dynamic(default)]
pub show_pane_ids: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromDynamic, ToDynamic)]
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ As features stabilize some brief notes about them will accumulate here.
their own new Short Codes section.
* CharSelect now shows emoji variations such as skin tones
* Improved fuzzy matching performance in CharSelect
* [PaneSelect](config/lua/keyassignment/PaneSelect.md) new modes `MoveToNewTab`
and `MoveToNewWindow`, as well as `show_pane_ids=true` to show the pane ids.
#4147

#### New
* [wezterm imgcat](cli/imgcat.md) now has `--position`, `--no-move-cursor` and
Expand Down
9 changes: 9 additions & 0 deletions docs/config/lua/keyassignment/PaneSelect.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ The available actions are:

The selection alphabet defaults to the same value as [quick_select_alphabet](../config/quick_select_alphabet.md), but can be explicitly via the `alphabet` field:

{{since('nightly')}}

Additional modes are now supported:

* `mode="MoveToNewTab"` - moves the selected pane into a new tab in the same window, and activates it
* `mode="MoveToNewWindow"` - moves the selected pane into a new window, and activates it

You may now also set `show_pane_ids=true` to show the pane id alongside the label.

```lua
local wezterm = require 'wezterm'
local act = wezterm.action
Expand Down
59 changes: 57 additions & 2 deletions wezterm-gui/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,14 +797,50 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option<Comm
menubar: &["Edit"],
icon: Some("md_sticker_emoji"),
},
PaneSelect(_) => CommandDef {
PaneSelect(PaneSelectArguments {
mode: PaneSelectMode::Activate,
..
}) => CommandDef {
brief: "Enter Pane selection mode".into(),
doc: "Activates the pane selection UI".into(),
keys: vec![], // FIXME: find a new assignment
args: &[ArgType::ActivePane],
menubar: &["Window"],
icon: Some("cod_multiple_windows"),
},
PaneSelect(PaneSelectArguments {
mode: PaneSelectMode::SwapWithActive,
..
}) => CommandDef {
brief: "Swap a pane with the active pane".into(),
doc: "Activates the pane selection UI".into(),
keys: vec![], // FIXME: find a new assignment
args: &[ArgType::ActivePane],
menubar: &["Window"],
icon: Some("cod_multiple_windows"),
},
PaneSelect(PaneSelectArguments {
mode: PaneSelectMode::MoveToNewTab,
..
}) => CommandDef {
brief: "Move a pane into its own tab".into(),
doc: "Activates the pane selection UI".into(),
keys: vec![], // FIXME: find a new assignment
args: &[ArgType::ActivePane],
menubar: &["Window"],
icon: Some("cod_multiple_windows"),
},
PaneSelect(PaneSelectArguments {
mode: PaneSelectMode::MoveToNewWindow,
..
}) => CommandDef {
brief: "Move a pane into its own window".into(),
doc: "Activates the pane selection UI".into(),
keys: vec![], // FIXME: find a new assignment
args: &[ArgType::ActivePane],
menubar: &["Window"],
icon: Some("cod_multiple_windows"),
},
DecreaseFontSize => CommandDef {
brief: "Decrease font size".into(),
doc: "Scales the font size smaller by 10%".into(),
Expand Down Expand Up @@ -1971,7 +2007,26 @@ fn compute_default_actions() -> Vec<KeyAssignment> {
ToggleFullScreen,
Hide,
Search(Pattern::CurrentSelectionOrEmptyString),
PaneSelect(PaneSelectArguments::default()),
PaneSelect(PaneSelectArguments {
alphabet: String::new(),
mode: PaneSelectMode::Activate,
show_pane_ids: false,
}),
PaneSelect(PaneSelectArguments {
alphabet: String::new(),
mode: PaneSelectMode::SwapWithActive,
show_pane_ids: false,
}),
PaneSelect(PaneSelectArguments {
alphabet: String::new(),
mode: PaneSelectMode::MoveToNewTab,
show_pane_ids: false,
}),
PaneSelect(PaneSelectArguments {
alphabet: String::new(),
mode: PaneSelectMode::MoveToNewWindow,
show_pane_ids: false,
}),
RotatePanes(RotationDirection::Clockwise),
RotatePanes(RotationDirection::CounterClockwise),
ActivateTab(0),
Expand Down
39 changes: 37 additions & 2 deletions wezterm-gui/src/termwindow/paneselect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct PaneSelector {
alphabet: String,
mode: PaneSelectMode,
was_zoomed: bool,
show_pane_ids: bool,
}

impl PaneSelector {
Expand All @@ -45,12 +46,14 @@ impl PaneSelector {
alphabet,
mode: args.mode,
was_zoomed,
show_pane_ids: args.show_pane_ids,
}
}

fn compute(
term_window: &mut TermWindow,
alphabet: &str,
show_pane_ids: bool,
) -> anyhow::Result<(Vec<ComputedElement>, Vec<String>)> {
let font = term_window
.fonts
Expand All @@ -73,7 +76,11 @@ impl PaneSelector {

let mut elements = vec![];
for pos in panes {
let caption = labels[pos.index].clone();
let caption = if show_pane_ids {
format!("{}: {}", labels[pos.index], pos.pane.pane_id())
} else {
labels[pos.index].clone()
};
let element = Element::new(&font, ElementContent::Text(caption))
.colors(ElementColors {
border: BorderColor::new(
Expand Down Expand Up @@ -175,6 +182,34 @@ impl PaneSelector {
PaneSelectMode::SwapWithActive => {
tab.swap_active_with_index(pane_index);
}
PaneSelectMode::MoveToNewWindow => {
if let Some(pos) = panes.iter().find(|p| p.index == pane_index) {
let pane_id = pos.pane.pane_id();
promise::spawn::spawn(async move {
if let Err(err) = mux.move_pane_to_new_tab(pane_id, None, None).await {
log::error!("failed to move_pane_to_new_tab: {err:#}");
}
})
.detach();
}
}
PaneSelectMode::MoveToNewTab => {
if let Some(pos) = panes.iter().find(|p| p.index == pane_index) {
let pane_id = pos.pane.pane_id();
let window_id = term_window.mux_window_id;
promise::spawn::spawn(async move {
if let Err(err) = mux
.move_pane_to_new_tab(pane_id, Some(window_id), None)
.await
{
log::error!("failed to move_pane_to_new_tab: {err:#}");
}

mux.focus_pane_and_containing_tab(pane_id).ok();
})
.detach();
}
}
}
}

Expand Down Expand Up @@ -242,7 +277,7 @@ impl Modal for PaneSelector {
term_window: &mut TermWindow,
) -> anyhow::Result<Ref<[ComputedElement]>> {
if self.element.borrow().is_none() {
let (element, labels) = Self::compute(term_window, &self.alphabet)?;
let (element, labels) = Self::compute(term_window, &self.alphabet, self.show_pane_ids)?;
self.element.borrow_mut().replace(element);
*self.labels.borrow_mut() = labels;
}
Expand Down

0 comments on commit a9c7d28

Please sign in to comment.