Skip to content

Commit cfbde91

Browse files
terminal: Add setting for scroll multiplier (#39463)
Closes #5130 Release Notes: - Added setting option for scroll multiplier of the terminal --------- Signed-off-by: Marco Mihai Condrache <[email protected]> Co-authored-by: MrSubidubi <[email protected]>
1 parent 80b32dd commit cfbde91

File tree

8 files changed

+63
-12
lines changed

8 files changed

+63
-12
lines changed

assets/settings/default.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,8 @@
15501550
// Default: 10_000, maximum: 100_000 (all bigger values set will be treated as 100_000), 0 disables the scrolling.
15511551
// Existing terminals will not pick up this change until they are recreated.
15521552
"max_scroll_history_lines": 10000,
1553+
// The multiplier for scrolling speed in the terminal.
1554+
"scroll_multiplier": 1.0,
15531555
// The minimum APCA perceptual contrast between foreground and background colors.
15541556
// APCA (Accessible Perceptual Contrast Algorithm) is more accurate than WCAG 2.x,
15551557
// especially for dark mode. Values range from 0 to 106.

crates/settings/src/settings_content/terminal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ pub struct TerminalSettingsContent {
116116
///
117117
/// Default: 10_000
118118
pub max_scroll_history_lines: Option<usize>,
119+
/// The multiplier for scrolling with the mouse wheel.
120+
///
121+
/// Default: 1.0
122+
pub scroll_multiplier: Option<f32>,
119123
/// Toolbar related settings
120124
pub toolbar: Option<TerminalToolbarContent>,
121125
/// Scrollbar-related settings

crates/settings/src/vscode_import.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ impl VsCodeSettings {
737737
option_as_meta: self.read_bool("terminal.integrated.macOptionIsMeta"),
738738
project: self.project_terminal_settings_content(),
739739
scrollbar: None,
740+
scroll_multiplier: None,
740741
toolbar: None,
741742
})
742743
}

crates/settings_ui/src/page_data.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5168,6 +5168,24 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
51685168
metadata: None,
51695169
files: USER,
51705170
}),
5171+
SettingsPageItem::SettingItem(SettingItem {
5172+
title: "Scroll Multiplier",
5173+
description: "The multiplier for scrolling in the terminal with the mouse wheel",
5174+
field: Box::new(SettingField {
5175+
json_path: Some("terminal.scroll_multiplier"),
5176+
pick: |settings_content| {
5177+
settings_content.terminal.as_ref()?.scroll_multiplier.as_ref()
5178+
},
5179+
write: |settings_content, value| {
5180+
settings_content
5181+
.terminal
5182+
.get_or_insert_default()
5183+
.scroll_multiplier = value;
5184+
},
5185+
}),
5186+
metadata: None,
5187+
files: USER,
5188+
}),
51715189
SettingsPageItem::SectionHeader("Toolbar"),
51725190
SettingsPageItem::SettingItem(SettingItem {
51735191
title: "Breadcrumbs",

crates/terminal/src/terminal.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ actions!(
108108
]
109109
);
110110

111-
///Scrolling is unbearably sluggish by default. Alacritty supports a configurable
112-
///Scroll multiplier that is set to 3 by default. This will be removed when I
113-
///Implement scroll bars.
114-
#[cfg(target_os = "macos")]
115-
const SCROLL_MULTIPLIER: f32 = 4.;
116-
#[cfg(not(target_os = "macos"))]
117-
const SCROLL_MULTIPLIER: f32 = 1.;
118111
const DEBUG_TERMINAL_WIDTH: Pixels = px(500.);
119112
const DEBUG_TERMINAL_HEIGHT: Pixels = px(30.);
120113
const DEBUG_CELL_WIDTH: Pixels = px(5.);
@@ -1890,10 +1883,11 @@ impl Terminal {
18901883
}
18911884

18921885
///Scroll the terminal
1893-
pub fn scroll_wheel(&mut self, e: &ScrollWheelEvent) {
1886+
pub fn scroll_wheel(&mut self, e: &ScrollWheelEvent, scroll_multiplier: f32) {
18941887
let mouse_mode = self.mouse_mode(e.shift);
1888+
let scroll_multiplier = if mouse_mode { 1. } else { scroll_multiplier };
18951889

1896-
if let Some(scroll_lines) = self.determine_scroll_lines(e, mouse_mode) {
1890+
if let Some(scroll_lines) = self.determine_scroll_lines(e, scroll_multiplier) {
18971891
if mouse_mode {
18981892
let point = grid_point(
18991893
e.position - self.last_content.terminal_bounds.bounds.origin,
@@ -1926,8 +1920,11 @@ impl Terminal {
19261920
self.word_from_position(window.mouse_position());
19271921
}
19281922

1929-
fn determine_scroll_lines(&mut self, e: &ScrollWheelEvent, mouse_mode: bool) -> Option<i32> {
1930-
let scroll_multiplier = if mouse_mode { 1. } else { SCROLL_MULTIPLIER };
1923+
fn determine_scroll_lines(
1924+
&mut self,
1925+
e: &ScrollWheelEvent,
1926+
scroll_multiplier: f32,
1927+
) -> Option<i32> {
19311928
let line_height = self.last_content.terminal_bounds.line_height;
19321929
match e.touch_phase {
19331930
/* Reset scroll state on started */

crates/terminal/src/terminal_settings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use schemars::JsonSchema;
77
use serde::{Deserialize, Serialize};
88

99
pub use settings::AlternateScroll;
10+
1011
use settings::{
1112
RegisterSetting, ShowScrollbar, TerminalBlink, TerminalDockPosition, TerminalLineHeight,
1213
VenvSettings, WorkingDirectory, merge_from::MergeFrom,
@@ -42,6 +43,7 @@ pub struct TerminalSettings {
4243
pub default_height: Pixels,
4344
pub detect_venv: VenvSettings,
4445
pub max_scroll_history_lines: Option<usize>,
46+
pub scroll_multiplier: f32,
4547
pub toolbar: Toolbar,
4648
pub scrollbar: ScrollbarSettings,
4749
pub minimum_contrast: f32,
@@ -105,6 +107,7 @@ impl settings::Settings for TerminalSettings {
105107
default_width: px(user_content.default_width.unwrap()),
106108
default_height: px(user_content.default_height.unwrap()),
107109
detect_venv: project_content.detect_venv.unwrap(),
110+
scroll_multiplier: user_content.scroll_multiplier.unwrap(),
108111
max_scroll_history_lines: user_content.max_scroll_history_lines,
109112
toolbar: Toolbar {
110113
breadcrumbs: user_content.toolbar.unwrap().breadcrumbs.unwrap(),

crates/terminal_view/src/terminal_view.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,12 @@ impl TerminalView {
519519
return;
520520
}
521521
}
522-
self.terminal.update(cx, |term, _| term.scroll_wheel(event));
522+
self.terminal.update(cx, |term, cx| {
523+
term.scroll_wheel(
524+
event,
525+
TerminalSettings::get_global(cx).scroll_multiplier.max(0.01),
526+
)
527+
});
523528
}
524529

525530
fn scroll_line_up(&mut self, _: &ScrollLineUp, _: &mut Window, cx: &mut Context<Self>) {

docs/src/configuring-zed.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,6 +3586,7 @@ List of `integer` column numbers
35863586
"option_as_meta": false,
35873587
"button": true,
35883588
"shell": "system",
3589+
"scroll_multiplier": 3.0,
35893590
"toolbar": {
35903591
"breadcrumbs": false
35913592
},
@@ -3998,6 +3999,26 @@ Disable with:
39983999
}
39994000
```
40004001

4002+
### Terminal: Scroll Multiplier
4003+
4004+
- Description: The multiplier for scrolling speed in the terminal when using mouse wheel or trackpad.
4005+
- Setting: `scroll_multiplier`
4006+
- Default: `1.0`
4007+
4008+
**Options**
4009+
4010+
Positive floating point values. Values less than or equal to 0 will be clamped to a minimum of 0.01.
4011+
4012+
**Example**
4013+
4014+
```json
4015+
{
4016+
"terminal": {
4017+
"scroll_multiplier": 5.0
4018+
}
4019+
}
4020+
```
4021+
40014022
## Terminal: Toolbar
40024023

40034024
- Description: Whether or not to show various elements in the terminal toolbar.

0 commit comments

Comments
 (0)