Add CopyPrimary keybinding action on Linux/BSD

This commit is contained in:
Kirill Chibisov 2020-03-24 02:46:33 +03:00 committed by GitHub
parent a2875454b1
commit c9c5fbbe2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 16 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Default Command+N keybinding for SpawnNewInstance on macOS - Default Command+N keybinding for SpawnNewInstance on macOS
- Vi mode for copying text and opening links - Vi mode for copying text and opening links
- `CopySelection` action which copies into selection buffer on Linux/BSD
### Changed ### Changed

View File

@ -504,6 +504,9 @@
# (macOS only): # (macOS only):
# - ToggleSimpleFullscreen: Enters fullscreen without occupying another space # - ToggleSimpleFullscreen: Enters fullscreen without occupying another space
# #
# (Linux/BSD only):
# - CopySelection: Copies into selection buffer
#
# - `command`: Fork and execute a specified command plus arguments # - `command`: Fork and execute a specified command plus arguments
# #
# The `command` field must be a map containing a `program` string and an # The `command` field must be a map containing a `program` string and an
@ -569,6 +572,8 @@
#- { key: U, mods: Control, mode: Vi, action: ScrollHalfPageUp } #- { key: U, mods: Control, mode: Vi, action: ScrollHalfPageUp }
#- { key: D, mods: Control, mode: Vi, action: ScrollHalfPageDown } #- { key: D, mods: Control, mode: Vi, action: ScrollHalfPageDown }
#- { key: Y, mode: Vi, action: Copy } #- { key: Y, mode: Vi, action: Copy }
#- { key: Y, mode: Vi, action: ClearSelection }
#- { key: Copy, mode: Vi, action: ClearSelection }
#- { key: V, mode: Vi, action: ToggleNormalSelection } #- { key: V, mode: Vi, action: ToggleNormalSelection }
#- { key: V, mods: Shift, mode: Vi, action: ToggleLineSelection } #- { key: V, mods: Shift, mode: Vi, action: ToggleLineSelection }
#- { key: V, mods: Control, mode: Vi, action: ToggleBlockSelection } #- { key: V, mods: Control, mode: Vi, action: ToggleBlockSelection }
@ -597,14 +602,15 @@
#- { key: Key5, mods: Shift, mode: Vi, action: Bracket } #- { key: Key5, mods: Shift, mode: Vi, action: Bracket }
# (Windows, Linux, and BSD only) # (Windows, Linux, and BSD only)
#- { key: V, mods: Control|Shift, action: Paste } #- { key: V, mods: Control|Shift, action: Paste }
#- { key: C, mods: Control|Shift, action: Copy } #- { key: C, mods: Control|Shift, action: Copy }
#- { key: Insert, mods: Shift, action: PasteSelection } #- { key: C, mods: Control|Shift, mode: Vi, action: ClearSelection }
#- { key: Key0, mods: Control, action: ResetFontSize } #- { key: Insert, mods: Shift, action: PasteSelection }
#- { key: Equals, mods: Control, action: IncreaseFontSize } #- { key: Key0, mods: Control, action: ResetFontSize }
#- { key: Add, mods: Control, action: IncreaseFontSize } #- { key: Equals, mods: Control, action: IncreaseFontSize }
#- { key: Subtract, mods: Control, action: DecreaseFontSize } #- { key: Add, mods: Control, action: IncreaseFontSize }
#- { key: Minus, mods: Control, action: DecreaseFontSize } #- { key: Subtract, mods: Control, action: DecreaseFontSize }
#- { key: Minus, mods: Control, action: DecreaseFontSize }
# (Windows only) # (Windows only)
#- { key: Return, mods: Alt, action: ToggleFullscreen } #- { key: Return, mods: Alt, action: ToggleFullscreen }
@ -618,6 +624,7 @@
#- { key: K, mods: Command, action: ClearHistory } #- { key: K, mods: Command, action: ClearHistory }
#- { key: V, mods: Command, action: Paste } #- { key: V, mods: Command, action: Paste }
#- { key: C, mods: Command, action: Copy } #- { key: C, mods: Command, action: Copy }
#- { key: C, mods: Command, mode: Vi, action: ClearSelection }
#- { key: H, mods: Command, action: Hide } #- { key: H, mods: Command, action: Hide }
#- { key: M, mods: Command, action: Minimize } #- { key: M, mods: Command, action: Minimize }
#- { key: Q, mods: Command, action: Quit } #- { key: Q, mods: Command, action: Quit }

View File

@ -111,6 +111,10 @@ pub enum Action {
/// Store current selection into clipboard. /// Store current selection into clipboard.
Copy, Copy,
#[cfg(not(any(target_os = "macos", windows)))]
/// Store current selection into selection buffer.
CopySelection,
/// Paste contents of selection buffer. /// Paste contents of selection buffer.
PasteSelection, PasteSelection,
@ -297,6 +301,7 @@ pub fn default_key_bindings() -> Vec<KeyBinding> {
let mut bindings = bindings!( let mut bindings = bindings!(
KeyBinding; KeyBinding;
Copy; Action::Copy; Copy; Action::Copy;
Copy, +TermMode::VI; Action::ClearSelection;
Paste, ~TermMode::VI; Action::Paste; Paste, ~TermMode::VI; Action::Paste;
L, ModifiersState::CTRL; Action::ClearLogNotice; L, ModifiersState::CTRL; Action::ClearLogNotice;
L, ModifiersState::CTRL, ~TermMode::VI; Action::Esc("\x0c".into()); L, ModifiersState::CTRL, ~TermMode::VI; Action::Esc("\x0c".into());
@ -366,6 +371,7 @@ pub fn default_key_bindings() -> Vec<KeyBinding> {
U, ModifiersState::CTRL, +TermMode::VI; Action::ScrollHalfPageUp; U, ModifiersState::CTRL, +TermMode::VI; Action::ScrollHalfPageUp;
D, ModifiersState::CTRL, +TermMode::VI; Action::ScrollHalfPageDown; D, ModifiersState::CTRL, +TermMode::VI; Action::ScrollHalfPageDown;
Y, +TermMode::VI; Action::Copy; Y, +TermMode::VI; Action::Copy;
Y, +TermMode::VI; Action::ClearSelection;
V, +TermMode::VI; ViAction::ToggleNormalSelection; V, +TermMode::VI; ViAction::ToggleNormalSelection;
V, ModifiersState::SHIFT, +TermMode::VI; ViAction::ToggleLineSelection; V, ModifiersState::SHIFT, +TermMode::VI; ViAction::ToggleLineSelection;
V, ModifiersState::CTRL, +TermMode::VI; ViAction::ToggleBlockSelection; V, ModifiersState::CTRL, +TermMode::VI; ViAction::ToggleBlockSelection;
@ -472,6 +478,7 @@ fn common_keybindings() -> Vec<KeyBinding> {
KeyBinding; KeyBinding;
V, ModifiersState::CTRL | ModifiersState::SHIFT, ~TermMode::VI; Action::Paste; V, ModifiersState::CTRL | ModifiersState::SHIFT, ~TermMode::VI; Action::Paste;
C, ModifiersState::CTRL | ModifiersState::SHIFT; Action::Copy; C, ModifiersState::CTRL | ModifiersState::SHIFT; Action::Copy;
C, ModifiersState::CTRL | ModifiersState::SHIFT, +TermMode::VI; Action::ClearSelection;
Insert, ModifiersState::SHIFT, ~TermMode::VI; Action::PasteSelection; Insert, ModifiersState::SHIFT, ~TermMode::VI; Action::PasteSelection;
Key0, ModifiersState::CTRL; Action::ResetFontSize; Key0, ModifiersState::CTRL; Action::ResetFontSize;
Equals, ModifiersState::CTRL; Action::IncreaseFontSize; Equals, ModifiersState::CTRL; Action::IncreaseFontSize;
@ -511,6 +518,7 @@ pub fn platform_key_bindings() -> Vec<KeyBinding> {
F, ModifiersState::CTRL | ModifiersState::LOGO; Action::ToggleFullscreen; F, ModifiersState::CTRL | ModifiersState::LOGO; Action::ToggleFullscreen;
K, ModifiersState::LOGO; Action::ClearHistory; K, ModifiersState::LOGO; Action::ClearHistory;
C, ModifiersState::LOGO; Action::Copy; C, ModifiersState::LOGO; Action::Copy;
C, ModifiersState::LOGO, +TermMode::VI; Action::ClearSelection;
H, ModifiersState::LOGO; Action::Hide; H, ModifiersState::LOGO; Action::Hide;
M, ModifiersState::LOGO; Action::Minimize; M, ModifiersState::LOGO; Action::Minimize;
Q, ModifiersState::LOGO; Action::Quit; Q, ModifiersState::LOGO; Action::Quit;

View File

@ -132,14 +132,9 @@ impl<T: EventListener> Execute<T> for Action {
ctx.scroll(Scroll::Bottom); ctx.scroll(Scroll::Bottom);
ctx.write_to_pty(s.clone().into_bytes()) ctx.write_to_pty(s.clone().into_bytes())
}, },
Action::Copy => { Action::Copy => ctx.copy_selection(ClipboardType::Clipboard),
ctx.copy_selection(ClipboardType::Clipboard); #[cfg(not(any(target_os = "macos", windows)))]
Action::CopySelection => ctx.copy_selection(ClipboardType::Selection),
// Clear selection in vi mode for better user feedback
if ctx.terminal().mode().contains(TermMode::VI) {
ctx.clear_selection();
}
},
Action::Paste => { Action::Paste => {
let text = ctx.terminal_mut().clipboard().load(ClipboardType::Clipboard); let text = ctx.terminal_mut().clipboard().load(ClipboardType::Clipboard);
paste(ctx, &text); paste(ctx, &text);