fix: smooth terminal font zooming using scroll accumulator

This commit is contained in:
TomZz
2026-06-27 00:23:20 +08:00
parent 77a0380ba7
commit 8cc64acdc1
2 changed files with 18 additions and 7 deletions
+2
View File
@@ -243,6 +243,7 @@ pub(crate) struct Ashell {
pub(crate) dark_theme_name: SharedString,
pub(crate) ui_font_size: f32,
pub(crate) terminal_font_size: f32,
pub(crate) terminal_zoom_accumulator: f32,
pub(crate) ui_font_family: SharedString,
pub(crate) terminal_font_family: SharedString,
pub(crate) tabs: Vec<TerminalTab>,
@@ -585,6 +586,7 @@ impl Ashell {
dark_theme_name,
ui_font_size: config.ui_font_size(),
terminal_font_size: config.terminal_font_size(),
terminal_zoom_accumulator: 0.0,
cursor_style: config.cursor_style(),
ui_font_family,
terminal_font_family,
+16 -7
View File
@@ -213,7 +213,12 @@ impl Ashell {
.and_then(|tab| tab.selection_text())
}
pub(crate) fn paste_into_terminal(&mut self, text: &str, window: &mut Window, cx: &mut Context<Self>) {
pub(crate) fn paste_into_terminal(
&mut self,
text: &str,
window: &mut Window,
cx: &mut Context<Self>,
) {
let Some(active_id) = self.active_tab.clone() else {
return;
};
@@ -481,14 +486,18 @@ impl Ashell {
window: &mut Window,
cx: &mut Context<Self>,
) {
// Ctrl+scroll → zoom terminal font size
if event.modifiers.control {
// Platform modifier (Cmd on macOS, Ctrl on Windows/Linux) + scroll → zoom terminal font size
if event.modifiers.platform {
let delta = match event.delta {
ScrollDelta::Lines(point) => point.y as f32,
ScrollDelta::Pixels(point) => point.y.as_f32() / 100.0,
ScrollDelta::Lines(point) => point.y as f32 * 20.0,
ScrollDelta::Pixels(point) => point.y.as_f32(),
};
if delta != 0.0 {
self.change_terminal_font_size(delta.signum() * 0.5, cx);
self.terminal_zoom_accumulator += delta;
let step = 20.0;
if self.terminal_zoom_accumulator.abs() >= step {
let zoom_steps = (self.terminal_zoom_accumulator / step).trunc();
self.terminal_zoom_accumulator -= zoom_steps * step;
self.change_terminal_font_size(zoom_steps * 0.5, cx);
}
window.prevent_default();
cx.stop_propagation();