From 8f2059e580e8e5afcd744c3c8758484cb42ee6fd Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 21 Apr 2022 07:56:35 -0700 Subject: [PATCH] docs for https://github.com/wez/wezterm/issues/1900 --- docs/changelog.md | 1 + .../lua/keyassignment/ClearSelection.md | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 docs/config/lua/keyassignment/ClearSelection.md diff --git a/docs/changelog.md b/docs/changelog.md index 8dc5e3407..2528a01a3 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -21,6 +21,7 @@ As features stabilize some brief notes about them will accumulate here. * X11: wezterm now sets `_NET_WM_NAME` in addition to `WM_NAME` for clients that don't know how to fallback * [treat_east_asian_ambiguous_width_as_wide](config/lua/config/treat_east_asian_ambiguous_width_as_wide.md) for control over how ambiguous width characters are resolved. [#1888](https://github.com/wez/wezterm/issues/1888) * [clean_exit_codes](config/lua/config/clean_exit_codes.md) config to fine tune [exit_behavior](config/lua/config/exit_behavior.md) [#1889](https://github.com/wez/wezterm/issues/1889) +* [ClearSelection](config/lua/keyassignment/ClearSelection.md) key assignment [#1900](https://github.com/wez/wezterm/issues/1900) #### Changed * Debian packages now register wezterm as an alternative for `x-terminal-emulator`. Thanks to [@xpufx](https://github.com/xpufx)! [#1883](https://github.com/wez/wezterm/pull/1883) diff --git a/docs/config/lua/keyassignment/ClearSelection.md b/docs/config/lua/keyassignment/ClearSelection.md new file mode 100644 index 000000000..64bff5356 --- /dev/null +++ b/docs/config/lua/keyassignment/ClearSelection.md @@ -0,0 +1,36 @@ +# ClearSelection + +*Since: nightly builds only* + +Clears the selection in the current pane. + +This example shows how to rebind `CTRL-C` to copy to the clipboard +when there is a selection present (clearing it afterwards) or sending +CTRL-C to the terminal when there is no selection: + +```lua +local wezterm = require 'wezterm' + +return { + keys = { + { + key="c", + mods="CTRL", + action = wezterm.action_callback(function(window, pane) + local has_selection = window:get_selection_text_for_pane(pane) ~= "" + if has_selection then + window:perform_action( + wezterm.action{CopyTo="ClipboardAndPrimarySelection"}, + pane) + + window:perform_action("ClearSelection", pane) + else + window:perform_action( + wezterm.action{SendKey={key="c", mods="CTRL"}}, + pane) + end + end) + } + } +} +```