1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-20 03:09:06 +03:00

Process shift+pageup/down at the gui layer

Refs: https://github.com/wez/wezterm/issues/106
This commit is contained in:
Wez Furlong 2020-01-03 09:10:11 -08:00
parent 6183434bda
commit ef072255dd
4 changed files with 34 additions and 0 deletions

View File

@ -46,6 +46,8 @@ The default key bindings are:
| `SUPER+SHIFT` | `]` | `ActivateTabRelative(1)` |
| `CTRL+SHIFT` | `PAGEUP` | `MoveTabRelative(-1)` |
| `CTRL+SHIFT` | `PAGEDOWN` | `MoveTabRelative(1)` |
| `SHIFT` | `PAGEUP` | `ScrollByPage(-1)` |
| `SHIFT` | `PAGEDOWN` | `ScrollByPage(1)` |
These can be overridden using the `keys` section in your `~/.wezterm.toml` config file.
For example, you can disable a default assignment like this:
@ -113,6 +115,7 @@ specified via the `arg` key; see examples below.
| `CloseCurrentTab` | Equivalent to clicking the `x` on the window title bar to close it: Closes the current tab. If that was the last tab, closes that window. If that was the last window, wezterm terminates. |
| `MoveTabRelative` | Move the current tab relative to its peers. The `arg` value specifies an offset. eg: `-1` moves the tab to the left of the current tab, while `1` moves the tab to the right. |
| `MoveTab` | Move the tab so that it has the index specified by the `arg` value. eg: `0` moves the tab to be leftmost, while `1` moves the tab so that it is second tab from the left, and so on. |
| `ScrollByPage` | Adjusts the scroll position by the number of pages specified by the `arg` value. Negative values scroll upwards, while positive values scroll downwards. |
Example:

View File

@ -76,6 +76,12 @@ impl std::convert::TryInto<KeyAssignment> for &Key {
.ok_or_else(|| anyhow!("missing arg for {:?}", self))?
.parse()?,
),
KeyAction::ScrollByPage => KeyAssignment::ScrollByPage(
self.arg
.as_ref()
.ok_or_else(|| anyhow!("missing arg for {:?}", self))?
.parse()?,
),
})
}
}
@ -102,6 +108,7 @@ pub enum KeyAction {
ReloadConfiguration,
MoveTab,
MoveTabRelative,
ScrollByPage,
}
fn de_keycode<'de, D>(deserializer: D) -> Result<KeyCode, D::Error>

View File

@ -1087,6 +1087,26 @@ impl TermWindow {
Ok(())
}
fn scroll_by_page(&mut self, amount: isize) -> anyhow::Result<()> {
let mux = Mux::get().unwrap();
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
Some(tab) => tab,
None => return Ok(()),
};
let mut render = tab.renderer();
let dims = render.get_dimensions();
let position = self
.get_viewport(tab.tab_id())
.unwrap_or(dims.physical_top)
.saturating_add(amount * dims.viewport_rows as isize);
self.set_viewport(tab.tab_id(), Some(position), dims);
render.make_all_lines_dirty();
if let Some(win) = self.window.as_ref() {
win.invalidate();
}
Ok(())
}
fn move_tab_relative(&mut self, delta: isize) -> anyhow::Result<()> {
let mux = Mux::get().unwrap();
let window = mux
@ -1211,6 +1231,7 @@ impl TermWindow {
ReloadConfiguration => crate::config::reload(),
MoveTab(n) => self.move_tab(*n)?,
MoveTabRelative(n) => self.move_tab_relative(*n)?,
ScrollByPage(n) => self.scroll_by_page(*n)?,
};
Ok(())
}

View File

@ -37,6 +37,7 @@ pub enum KeyAssignment {
ReloadConfiguration,
MoveTabRelative(isize),
MoveTab(usize),
ScrollByPage(isize),
}
pub struct KeyMap(HashMap<(KeyCode, KeyModifiers), KeyAssignment>);
@ -143,6 +144,8 @@ impl KeyMap {
[ctrl_shift, KeyCode::Char('R'), ReloadConfiguration],
[ctrl_shift, KeyCode::PageUp, MoveTabRelative(-1)],
[ctrl_shift, KeyCode::PageDown, MoveTabRelative(1)],
[KeyModifiers::SHIFT, KeyCode::PageUp, ScrollByPage(-1)],
[KeyModifiers::SHIFT, KeyCode::PageDown, ScrollByPage(1)],
);
Self(map)