1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 13:21:38 +03:00

wezterm: change default copy/paste behavior on X11

This commit changes mouse-based selection and middle click to use the
PrimarySelection.

CTRL-SHIFT-{C,V} use Clipboard.

{SHIFT,CTRL}-Insert use PrimarySelection.

`CompleteSelection` and `CompleteSelectionOrOpenLinkAtMouseCursor` now
require a parameter to specify the destination clipboard.

Removed the `default_clipboard_XXX` options added in
8dad34fa61 in favor of just explicitly
assigning the key/mouse bindings.

closes: #417
This commit is contained in:
Wez Furlong 2021-01-31 09:28:42 -08:00
parent 9a610358d1
commit df3387e12c
12 changed files with 121 additions and 98 deletions

View File

@ -189,8 +189,8 @@ pub enum KeyAssignment {
SelectTextAtMouseCursor(SelectionMode),
ExtendSelectionToMouseCursor(Option<SelectionMode>),
OpenLinkAtMouseCursor,
CompleteSelection,
CompleteSelectionOrOpenLinkAtMouseCursor,
CompleteSelection(ClipboardCopyDestination),
CompleteSelectionOrOpenLinkAtMouseCursor(ClipboardCopyDestination),
AdjustPaneSize(PaneDirection, usize),
ActivatePaneDirection(PaneDirection),
@ -243,12 +243,36 @@ impl InputMap {
// a given entry then that will take precedence.
k!(
// Clipboard
[Modifiers::SHIFT, KeyCode::Insert, Paste],
[Modifiers::CTRL, KeyCode::Insert, Copy],
[Modifiers::SUPER, KeyCode::Char('c'), Copy],
[Modifiers::SUPER, KeyCode::Char('v'), Paste],
[Modifiers::CTRL, KeyCode::Char('C'), Copy],
[Modifiers::CTRL, KeyCode::Char('V'), Paste],
[
Modifiers::SHIFT,
KeyCode::Insert,
PasteFrom(ClipboardPasteSource::PrimarySelection)
],
[
Modifiers::CTRL,
KeyCode::Insert,
CopyTo(ClipboardCopyDestination::PrimarySelection)
],
[
Modifiers::SUPER,
KeyCode::Char('c'),
CopyTo(ClipboardCopyDestination::Clipboard)
],
[
Modifiers::SUPER,
KeyCode::Char('v'),
PasteFrom(ClipboardPasteSource::Clipboard)
],
[
Modifiers::CTRL,
KeyCode::Char('C'),
CopyTo(ClipboardCopyDestination::Clipboard)
],
[
Modifiers::CTRL,
KeyCode::Char('V'),
PasteFrom(ClipboardPasteSource::Clipboard)
],
// Window management
[Modifiers::ALT, KeyCode::Char('\n'), ToggleFullScreen],
[Modifiers::ALT, KeyCode::Char('\r'), ToggleFullScreen],
@ -458,7 +482,9 @@ impl InputMap {
streak: 1,
button: MouseButton::Left
},
CompleteSelectionOrOpenLinkAtMouseCursor
CompleteSelectionOrOpenLinkAtMouseCursor(
ClipboardCopyDestination::PrimarySelection
)
],
[
Modifiers::NONE,
@ -466,7 +492,7 @@ impl InputMap {
streak: 2,
button: MouseButton::Left
},
CompleteSelection
CompleteSelection(ClipboardCopyDestination::PrimarySelection)
],
[
Modifiers::NONE,
@ -474,7 +500,7 @@ impl InputMap {
streak: 3,
button: MouseButton::Left
},
CompleteSelection
CompleteSelection(ClipboardCopyDestination::PrimarySelection)
],
[
Modifiers::NONE,
@ -506,7 +532,7 @@ impl InputMap {
streak: 1,
button: MouseButton::Middle
},
Paste
PasteFrom(ClipboardPasteSource::PrimarySelection)
],
);
}

View File

@ -1,8 +1,6 @@
//! Configuration for the gui portion of the terminal
use crate::keyassignment::{
ClipboardCopyDestination, ClipboardPasteSource, KeyAssignment, MouseEventTrigger, SpawnCommand,
};
use crate::keyassignment::{KeyAssignment, MouseEventTrigger, SpawnCommand};
use anyhow::{anyhow, bail, Context, Error};
use lazy_static::lazy_static;
use luahelper::impl_lua_conversion;
@ -856,12 +854,6 @@ pub struct Config {
#[serde(default = "default_true")]
pub adjust_window_size_when_changing_font_size: bool,
#[serde(default = "default_copy_destination")]
pub default_clipboard_copy_destination: ClipboardCopyDestination,
#[serde(default = "default_paste_source")]
pub default_clipboard_paste_source: ClipboardPasteSource,
#[serde(default = "default_alternate_buffer_wheel_scroll_speed")]
pub alternate_buffer_wheel_scroll_speed: u8,
}
@ -1281,18 +1273,6 @@ impl Config {
}
}
fn default_copy_destination() -> ClipboardCopyDestination {
if cfg!(any(target_os = "macos", windows)) {
ClipboardCopyDestination::Clipboard
} else {
ClipboardCopyDestination::ClipboardAndPrimarySelection
}
}
fn default_paste_source() -> ClipboardPasteSource {
ClipboardPasteSource::Clipboard
}
fn default_ratelimit_line_prefetches_per_second() -> u32 {
10
}

View File

@ -49,8 +49,10 @@ brief notes about them may accumulate here.
* Windows: when pasting text, ensure that the text has CRLF line endings unless bracketed paste is enabled. This imperfect heuristic helps to keep multi-line pastes on multiple lines when using Windows console applications and to avoid interleaved blank lines when using unix applications. [#411](https://github.com/wez/wezterm/issues/411)
* New: [ClearScrollback](config/lua/keyassignment/ClearScrollback.html) now accepts a parameter to control whether the viewport is cleared along with the scrollback. Thanks to [@dfrankland](https://github.com/dfrankland)!
* New: [default_cwd](config/lua/config/default_cwd.html) to specify an alternative current working directory. Thanks to [@dfrankland](https://github.com/dfrankland)!
* New: [default_clipboard_copy_destination](config/lua/config/default_clipboard_copy_destination.md) and [default_clipboard_paste_source](config/lua/config/default_clipboard_paste_source.md) config options for X11, along with [CopyTo](config/lua/keyassignment/CopyTo.md) and [PasteFrom](config/lua/keyassignment/PasteFrom.md) actions. [PastePrimarySelection](config/lua/keyassignment/PastePrimarySelection.md) is now deprecated in favor of these new options.
* New: Added a new default `CTRL-Insert` key assignment bound to `Copy`
* New: [CopyTo](config/lua/keyassignment/CopyTo.md) and [PasteFrom](config/lua/keyassignment/PasteFrom.md) actions. [Copy](config/lua/keyassignment/Copy.md), [Paste](config/lua/keyassignment/Paste.md) and [PastePrimarySelection](config/lua/keyassignment/PastePrimarySelection.md) are now deprecated in favor of these new options.
* X11: Mouse-based selection now copies-to and pastes-from the `PrimarySelection` by default. The [CompleteSelection](config/lua/keyassignment/CompleteSelection.md) and [CompleteSelectionOrOpenLinkAtMouseCursor](config/lua/keyassignment/CompleteSelectionOrOpenLinkAtMouseCursor.md) actions now require a parameter to specify the clipboard.
* X11: `SHIFT-CTRL-C` and `SHIFT-CTRL-V` now copy-to and paste from the `Clipboard` by default. `SHIFT-Insert` pastes from the `PrimarySelection` by default.
* New: Added a new default `CTRL-Insert` key assignment bound to `CopyTo(PrimarySelection)`
* macOS: Windows now have drop-shadows when they are opaque. These were disabled due transparency support was added. Thanks to [Rice](https://github.com/fanzeyi)! [#445](https://github.com/wez/wezterm/pull/445)
* Unix: adjust font-config patterns to also match "dual spacing" fonts such as [Iosevka Term](https://typeof.net/Iosevka/). Thanks to [Leiser](https://github.com/leiserfg)! [#446](https://github.com/wez/wezterm/pull/446)
* New: Added [alternate_buffer_wheel_scroll_speed](config/lua/config/alternate_buffer_wheel_scroll_speed.md) option to control how many cursor key presses are generated by the mouse wheel when the alternate screen is active. The new default for this is a faster-than-previous-releases 3 lines per wheel tick. [#432](https://github.com/wez/wezterm/issues/432)

View File

@ -104,12 +104,12 @@ The default key bindings are:
| Modifiers | Key | Action |
| --------- | --- | ------ |
| `SUPER` | `c` | `Copy` |
| `SUPER` | `v` | `Paste` |
| `CTRL+SHIFT` | `c` | `Copy` |
| `CTRL+SHIFT` | `v` | `Paste` |
| `CTRL` | `Insert` | `Copy` (*since: nightly builds*) |
| `SHIFT` | `Insert` | `Paste` |
| `SUPER` | `c` | `CopyTo="Clipboard"` |
| `SUPER` | `v` | `PasteFrom="Clipboard"` |
| `CTRL+SHIFT` | `c` | `CopyTo="Clipboard"` |
| `CTRL+SHIFT` | `v` | `PasteFrom="Clipboard"` |
| `CTRL` | `Insert` | `CopyTo="PrimarySelection"` (*since: nightly builds*) |
| `SHIFT` | `Insert` | `PasteFrom="PrimarySelection"` |
| `SUPER` | `m` | `Hide` |
| `SUPER` | `n` | `SpawnWindow` |
| `CTRL+SHIFT` | `n` | `SpawnWindow` |
@ -195,13 +195,13 @@ that order.
| Double Left Down | `NONE` | `SelectTextAtMouseCursor="Word"` |
| Single Left Down | `NONE` | `SelectTextAtMouseCursor="Cell"` |
| Single Left Down | `SHIFT` | `ExtendSelectionToMouseCursor={}` |
| Single Left Up | `NONE` | `CompleteSelectionOrOpenLinkAtMouseCursor` |
| Double Left Up | `NONE` | `CompleteSelection` |
| Triple Left Up | `NONE` | `CompleteSelection` |
| Single Left Up | `NONE` | `CompleteSelectionOrOpenLinkAtMouseCursor="PrimarySelection"` |
| Double Left Up | `NONE` | `CompleteSelection="PrimarySelection"` |
| Triple Left Up | `NONE` | `CompleteSelection="PrimarySelection"` |
| Single Left Drag | `NONE` | `ExtendSelectionToMouseCursor="Cell"` |
| Double Left Drag | `NONE` | `ExtendSelectionToMouseCursor="Word"` |
| Triple Left Drag | `NONE` | `ExtendSelectionToMouseCursor="Line"` |
| Single Middle Down | `NONE` | `Paste` |
| Single Middle Down | `NONE` | `PasteFrom="PrimarySelection"` |
If you don't want the default assignments to be registered, you can
disable all of them with this configuration; if you chose to do this,
@ -236,7 +236,7 @@ return {
{
event={Up={streak=1, button="Left"}},
mods="NONE",
action="CompleteSelection",
action=wezterm.action{CompleteSelection="PrimarySelection"},
},
-- and make CTRL-Click open hyperlinks

View File

@ -1,16 +0,0 @@
# `default_clipboard_copy_destination`
*Since: nightly builds only*
Specifies which clipboard buffer should be populated by the [Copy](../keyassignment/Copy.md), [CompleteSelection](../keyassignment/CompleteSelection.md) and [CompleteSelectionOrOpenLinkAtMouseCursor](../keyassignment/CompleteSelectionOrOpenLinkAtMouseCursor.md) actions.
Possible values are:
* `Clipboard` - copy the text to the system clipboard.
* `PrimarySelection` - Copy the test to the primary selection buffer (applicable to X11 systems only)
* `ClipboardAndPrimarySelection` - Copy to both the clipboard and the primary selection.
The default value is `ClipboardAndPrimarySelection`.
Prior to the introduction of this option, the behavior was not configurable,
but had the same behavior as the default.

View File

@ -1,16 +0,0 @@
# `default_clipboard_paste_source`
*Since: nightly builds only*
Specifies which clipboard buffer should be read by the
[Paste](../keyassignment/Paste.md) action.
Possible values are:
* `Clipboard` - paste from the system clipboard
* `PrimarySelection` - paste from the primary selection buffer (applicable to X11 systems only)
The default value is `Clipboard`.
Prior to the introduction of this option, the behavior was not configurable,
but had the same behavior as the default.

View File

@ -4,4 +4,27 @@ Completes an active text selection process; the selection range is
marked closed and then the selected text is copied as though the
`Copy` action was executed.
*since: nightly*
`CompleteSelection` now requires a destination parameter to specify
which clipboard buffer the selection will populate; the copy action
is now equivalent to [CopyTo](CopyTo.md).
```lua
local wezterm = require 'wezterm';
return {
mouse_bindings = {
-- Change the default click behavior so that it only selects
-- text and doesn't open hyperlinks, and that it populates
-- the Clipboard rather the PrimarySelection which is part
-- of the default assignment for a left mouse click.
{
event={Up={streak=1, button="Left"}},
mods="NONE",
action=wezterm.action{CompleteSelection="Clipboard"},
},
},
}
```

View File

@ -5,3 +5,25 @@ triggered. Otherwise acts as though `OpenLinkAtMouseCursor` was
triggered.
*since: nightly*
`CompleteSelectionOrOpenLinkAtMouseCursor` now requires a destination parameter to specify
which clipboard buffer the selection will populate. The copy action
is now equivalent to [CopyTo](CopyTo.md).
```lua
local wezterm = require 'wezterm';
return {
mouse_bindings = {
-- Change the default click behavior so that it populates
-- the Clipboard rather the PrimarySelection.
{
event={Up={streak=1, button="Left"}},
mods="NONE",
action=wezterm.action{CompleteSelectionOrOpenLinkAtMouseCursor="Clipboard"},
},
},
}
```

View File

@ -2,7 +2,12 @@
Copy the selection to the clipboard.
The value of the [default_clipboard_copy_destination](../config/default_clipboard_copy_destination.md) configuration option specifies which clipboard buffer is populated.
*since: nightly*
This action is considered to be deprecated and will be removed in
a future release; please use [CopyTo](CopyTo.md) instead.
## Example
```lua

View File

@ -2,11 +2,12 @@
Paste the clipboard to the current pane.
On X11 systems that have multiple clipboards, the
[default_clipboard_paste_source](../config/default_clipboard_paste_source.md)
option specifies which source to use.
*since: nightly*
See also [PastePrimarySelection](PastePrimarySelection.md) and [PasteFrom](PasteFrom.md).
This action is considered to be deprecated and will be removed in
a future release; please use [PasteFrom](PasteFrom.md) instead.
## Example
```lua
local wezterm = require 'wezterm';

View File

@ -5,9 +5,8 @@ On other systems, this behaves identically to [Paste](Paste.md).
*since: nightly*
This action is considered to be deprecated; please consider
using either [PasteFrom](PasteFrom.md) or just [Paste](Paste.md)
and adjusting the new [default_clipboard_paste_source](../config/default_clipboard_paste_source.md) configuration option.
This action is considered to be deprecated and will be removed in
a future release; please use [PasteFrom](PasteFrom.md) instead.
## Example

View File

@ -1939,14 +1939,17 @@ impl TermWindow {
}
Copy => {
let text = self.selection_text(pane);
self.copy_to_clipboard(configuration().default_clipboard_copy_destination, text);
self.copy_to_clipboard(
ClipboardCopyDestination::ClipboardAndPrimarySelection,
text,
);
}
CopyTo(dest) => {
let text = self.selection_text(pane);
self.copy_to_clipboard(*dest, text);
}
Paste => {
self.paste_from_clipboard(pane, configuration().default_clipboard_paste_source);
self.paste_from_clipboard(pane, ClipboardPasteSource::Clipboard);
}
PastePrimarySelection => {
self.paste_from_clipboard(pane, ClipboardPasteSource::PrimarySelection);
@ -2088,13 +2091,10 @@ impl TermWindow {
}))
.detach();
}
CompleteSelectionOrOpenLinkAtMouseCursor => {
CompleteSelectionOrOpenLinkAtMouseCursor(dest) => {
let text = self.selection_text(pane);
if !text.is_empty() {
self.copy_to_clipboard(
configuration().default_clipboard_copy_destination,
text,
);
self.copy_to_clipboard(*dest, text);
let window = self.window.as_ref().unwrap();
window.invalidate();
} else {
@ -2102,13 +2102,10 @@ impl TermWindow {
.perform_key_assignment(pane, &KeyAssignment::OpenLinkAtMouseCursor);
}
}
CompleteSelection => {
CompleteSelection(dest) => {
let text = self.selection_text(pane);
if !text.is_empty() {
self.copy_to_clipboard(
configuration().default_clipboard_copy_destination,
text,
);
self.copy_to_clipboard(*dest, text);
let window = self.window.as_ref().unwrap();
window.invalidate();
}