Skip to content

Commit

Permalink
mux: add lua api equivalent to move-pane-to-new-tab
Browse files Browse the repository at this point in the history
refs: #3374
  • Loading branch information
wez committed Mar 26, 2023
1 parent d9d6b2a commit e56b169
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ As features stabilize some brief notes about them will accumulate here.
enables a nice translucent window effect. Thanks to @Gkirito! #3344
* [new-tab-button-click event](config/lua/window-events/new-tab-button-click.md)
allows overriding the effect of clicking the New Tab button. #323
* [pane:move_to_new_window()](config/lua/pane/move_to_new_window.md),
[pane:move_to_new_tab()](config/lua/pane/move_to_new_tab.md). #3374

#### Fixed
* ssh ProxyCommand didn't parse command lines containing `=` correctly. #3307
Expand Down
3 changes: 3 additions & 0 deletions docs/cli/cli/move-pane-to-new-tab.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ The following arguments modify the behavior:
* `--workspace WORKSPACE` - When using `--new-window`, use `WORKSPACE` as the name of the workspace for the newly created window rather than the default workspace name `"default"`.
* `--pane-id` - Specifies which pane to move. See also [Targeting Panes](index.md#targeting-panes).

See also: [pane:move_to_new_window()](../../config/lua/pane/move_to_new_window.md),
[pane:move_to_new_tab()](../../config/lua/pane/move_to_new_tab.md).

## Synopsis

```console
Expand Down
8 changes: 8 additions & 0 deletions docs/config/lua/pane/move_to_new_tab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# `pane:move_to_new_tab()`

{{since('nightly')}}

Creates a new tab in the window that contains `pane`, and moves `pane` into that tab.

See also [pane:move_to_new_window()](move_to_new_window.md),
[wezterm cli move-pane-to-new-tab](../../../cli/cli/move-pane-to-new-tab.md).
14 changes: 14 additions & 0 deletions docs/config/lua/pane/move_to_new_window.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# `pane:move_to_new_window([WORKSPACE])`

{{since('nightly')}}

Creates a window and moves `pane` into that window.

The *WORKSPACE* parameter is optional; if specified, it will be used
as the name of the workspace that should be associated with the new
window. Otherwise, the current active workspace will be used.

See also [pane:move_to_new_window()](move_to_new_window.md),
[wezterm cli move-pane-to-new-tab](../../../cli/cli/move-pane-to-new-tab.md).


26 changes: 26 additions & 0 deletions lua-api-crates/mux/src/pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,32 @@ impl UserData for MuxPane {
};
this.get_text_from_semantic_zone(zone)
});

methods.add_async_method("move_to_new_tab", |_lua, this, ()| async move {
let mux = Mux::get();
let (_domain, window_id, _tab) = mux
.resolve_pane_id(this.0)
.ok_or_else(|| mlua::Error::external(format!("pane {} not found", this.0)))?;
let (tab, window) = mux
.move_pane_to_new_tab(this.0, Some(window_id), None)
.await
.map_err(|e| mlua::Error::external(format!("{:#?}", e)))?;

Ok((MuxTab(tab.tab_id()), MuxWindow(window)))
});

methods.add_async_method(
"move_to_new_window",
|_lua, this, workspace: Option<String>| async move {
let mux = Mux::get();
let (tab, window) = mux
.move_pane_to_new_tab(this.0, None, workspace)
.await
.map_err(|e| mlua::Error::external(format!("{:#?}", e)))?;

Ok((MuxTab(tab.tab_id()), MuxWindow(window)))
},
);
}
}

Expand Down

0 comments on commit e56b169

Please sign in to comment.