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

copy mode: add CopyMode key assignment actions

Defines an assignment action for each of the pre-defined actions
in copy mode.

refs: https://github.com/wez/wezterm/issues/993
This commit is contained in:
Wez Furlong 2022-05-04 21:44:04 -07:00
parent 262531631c
commit de97f16d56
3 changed files with 62 additions and 1 deletions

View File

@ -365,9 +365,35 @@ pub enum KeyAssignment {
ClearKeyTableStack, ClearKeyTableStack,
DetachDomain(SpawnTabDomain), DetachDomain(SpawnTabDomain),
AttachDomain(String), AttachDomain(String),
CopyMode(CopyModeAssignment),
} }
impl_lua_conversion!(KeyAssignment); impl_lua_conversion!(KeyAssignment);
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub enum CopyModeAssignment {
MoveToViewportBottom,
MoveToViewportTop,
MoveToViewportMiddle,
MoveToScrollbackTop,
MoveToScrollbackBottom,
ToggleSelectionByCell,
MoveToStartOfLineContent,
MoveToEndOfLineContent,
MoveToStartOfLine,
MoveToStartOfNextLine,
MoveBackwardWord,
MoveForwardWord,
MoveRight,
MoveLeft,
MoveUp,
MoveDown,
PageUp,
PageDown,
Close,
}
impl_lua_conversion!(CopyModeAssignment);
pub type KeyTable = HashMap<(KeyCode, Modifiers), KeyTableEntry>; pub type KeyTable = HashMap<(KeyCode, Modifiers), KeyTableEntry>;
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]

View File

@ -1,6 +1,6 @@
use crate::selection::{SelectionCoordinate, SelectionRange}; use crate::selection::{SelectionCoordinate, SelectionRange};
use crate::termwindow::{TermWindow, TermWindowNotif}; use crate::termwindow::{TermWindow, TermWindowNotif};
use config::keyassignment::ScrollbackEraseMode; use config::keyassignment::{CopyModeAssignment, KeyAssignment, ScrollbackEraseMode};
use mux::domain::DomainId; use mux::domain::DomainId;
use mux::pane::{Pane, PaneId}; use mux::pane::{Pane, PaneId};
use mux::renderable::*; use mux::renderable::*;
@ -404,6 +404,38 @@ impl Pane for CopyOverlay {
Ok(()) Ok(())
} }
fn perform_assignment(&self, assignment: &KeyAssignment) -> bool {
use CopyModeAssignment::*;
match assignment {
KeyAssignment::CopyMode(assignment) => {
let mut render = self.render.borrow_mut();
match assignment {
MoveToViewportBottom => render.move_to_viewport_bottom(),
MoveToViewportTop => render.move_to_viewport_top(),
MoveToViewportMiddle => render.move_to_viewport_middle(),
MoveToScrollbackTop => render.move_to_top(),
MoveToScrollbackBottom => render.move_to_bottom(),
ToggleSelectionByCell => render.toggle_selection_by_cell(),
MoveToStartOfLineContent => render.move_to_start_of_line_content(),
MoveToEndOfLineContent => render.move_to_end_of_line_content(),
MoveToStartOfLine => render.move_to_start_of_line(),
MoveToStartOfNextLine => render.move_to_start_of_next_line(),
MoveBackwardWord => render.move_backward_one_word(),
MoveForwardWord => render.move_forward_one_word(),
MoveRight => render.move_right_single_cell(),
MoveLeft => render.move_left_single_cell(),
MoveUp => render.move_up_single_row(),
MoveDown => render.move_down_single_row(),
PageUp => render.page_up(),
PageDown => render.page_down(),
Close => render.close(),
}
true
}
_ => false,
}
}
fn key_down(&self, key: KeyCode, mods: KeyModifiers) -> anyhow::Result<()> { fn key_down(&self, key: KeyCode, mods: KeyModifiers) -> anyhow::Result<()> {
match (key, mods) { match (key, mods) {
(KeyCode::Char('c'), KeyModifiers::CTRL) (KeyCode::Char('c'), KeyModifiers::CTRL)

View File

@ -2404,6 +2404,9 @@ impl TermWindow {
}) })
.detach(); .detach();
} }
CopyMode(_) => {
// NOP here; handled by the overlay directly
}
}; };
Ok(()) Ok(())
} }