diff --git a/config/src/lib.rs b/config/src/lib.rs index b8e3aa5b6..b27911562 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -861,6 +861,13 @@ pub struct Config { #[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, +} + +fn default_alternate_buffer_wheel_scroll_speed() -> u8 { + 3 } fn default_word_boundary() -> String { diff --git a/config/src/terminal.rs b/config/src/terminal.rs index 912d2a580..5b9119dd2 100644 --- a/config/src/terminal.rs +++ b/config/src/terminal.rs @@ -30,4 +30,8 @@ impl wezterm_term::TerminalConfiguration for TermConfig { config.resolved_palette.clone().into() } + + fn alternate_buffer_wheel_scroll_speed(&self) -> u8 { + configuration().alternate_buffer_wheel_scroll_speed + } } diff --git a/docs/changelog.markdown b/docs/changelog.markdown index 6f0ae5ce9..c01cac160 100644 --- a/docs/changelog.markdown +++ b/docs/changelog.markdown @@ -53,6 +53,7 @@ brief notes about them may accumulate here. * New: Added a new default `CTRL-Insert` key assignment bound to `Copy` * 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) ### 20201101-103216-403d002d diff --git a/docs/config/lua/config/alternate_buffer_wheel_scroll_speed.md b/docs/config/lua/config/alternate_buffer_wheel_scroll_speed.md new file mode 100644 index 000000000..900633b49 --- /dev/null +++ b/docs/config/lua/config/alternate_buffer_wheel_scroll_speed.md @@ -0,0 +1,25 @@ +# `alternate_buffer_wheel_scroll_speed = 3` + +*Since: nightly builds* + +Normally the vertical mouse wheel will scroll the terminal viewport +so that different sections of the scrollback are visible. + +When an application activates the *Alternate Screen Buffer* (this is +common for "full screen" terminal programs such as pagers and editors), +the alternate screen doesn't have a scrollback. + +In this mode, if the application hasn't enabled mouse reporting, wezterm will +generate Arrow Up/Down key events when the vertical mouse wheel is scrolled. + +The `alternate_buffer_wheel_scroll_speed` specifies how many arrow key presses +are generated by a single scroll wheel "tick". + +The default for this value is `3`, which means that a single wheel up tick will +appear to the application as though the user pressed arrow up three times in +quick succession. + +In versions of wezterm prior to this configuration option being available, the +behavior was the same except that the effective value of this option was always +`1`. + diff --git a/term/src/config.rs b/term/src/config.rs index 5c2db2c7b..90f36943c 100644 --- a/term/src/config.rs +++ b/term/src/config.rs @@ -68,4 +68,8 @@ pub trait TerminalConfiguration: std::fmt::Debug { fn resize_preserves_scrollback(&self) -> bool { cfg!(windows) } + + fn alternate_buffer_wheel_scroll_speed(&self) -> u8 { + 3 + } } diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index cb5440f43..dcd863e8a 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -531,14 +531,16 @@ impl TerminalState { self.writer.flush()?; } else if self.screen.is_alt_screen_active() { // Send cursor keys instead (equivalent to xterm's alternateScroll mode) - self.key_down( - match event.button { - MouseButton::WheelDown(_) => KeyCode::DownArrow, - MouseButton::WheelUp(_) => KeyCode::UpArrow, - _ => bail!("unexpected mouse event"), - }, - KeyModifiers::default(), - )?; + for _ in 0..self.config.alternate_buffer_wheel_scroll_speed() { + self.key_down( + match event.button { + MouseButton::WheelDown(_) => KeyCode::DownArrow, + MouseButton::WheelUp(_) => KeyCode::UpArrow, + _ => bail!("unexpected mouse event"), + }, + KeyModifiers::default(), + )?; + } } Ok(()) }