add window:get_selection_text_for_pane
refs: https://github.com/wez/wezterm/issues/575
This commit is contained in:
1 parent
1a7d3828fd
commit
0643e8b0ed
3 files changed
+39
No files matched your search
@@ -26,6 +26,7 @@ brief notes about them may accumulate here.
|
||||
* Fixed: triggering the search overlay again while the search overlay is active no longer closes the underlying pane [#572](https://github.com/wez/wezterm/issues/572)
|
||||
* Fixed: X10 mouse coordinate reporting encoding could produce invalid outputs for large windows. Capped coordinate values to the maximum value that is representable in UTF-8 encoding
|
||||
* Fixed: font fallback now happens asynchronously from painting [#508](https://github.com/wez/wezterm/issues/508)
|
||||
* New: added [window:get_selection_text_for_pane](config/lua/window/get_selection_text_for_pane.md) method [#575](https://github.com/wez/wezterm/issues/575)
|
||||
|
||||
### 20210314-114017-04b7cedd
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# `window:get_selection_text_for_pane(pane)`
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Returns the text that is currently selected within the specified pane within
|
||||
the specified window. This is the same text that would be copied to the
|
||||
clipboard if the [CopyTo](../keyassignment/CopyTo.md) action were to be
|
||||
performed.
|
||||
|
||||
Why isn't this simply a method of the `pane` object? The reason is that the
|
||||
selection is an attribute of the containing window, and a given pane can
|
||||
potentially be mapped into multiple windows.
|
||||
|
||||
This example logs the current selection when a CTRL+SHIFT+E is pressed:
|
||||
|
||||
```lua
|
||||
local wezterm = require 'wezterm';
|
||||
|
||||
wezterm.on("log-selection", function(window, pane)
|
||||
local sel = window:get_selection_text_for_pane(pane);
|
||||
wezterm.log_info("selection is: " .. sel)
|
||||
end)
|
||||
|
||||
return {
|
||||
keys = {
|
||||
{key="E", mods="CTRL", action=wezterm.action{EmitEvent="log-selection"}},
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -79,6 +79,15 @@ impl UserData for GuiWin {
|
||||
})
|
||||
.await
|
||||
});
|
||||
methods.add_async_method(
|
||||
"get_selection_text_for_pane",
|
||||
|_, this, pane: PaneObject| async move {
|
||||
this.with_term_window(move |term_window, _ops| {
|
||||
Ok(term_window.selection_text(&pane.pane()?))
|
||||
})
|
||||
.await
|
||||
},
|
||||
);
|
||||
methods.add_async_method(
|
||||
"perform_action",
|
||||
|_, this, (assignment, pane): (KeyAssignment, PaneObject)| async move {
|
||||
|
||||
Reference in new issue
Block a user