diff --git a/zed/src/editor/element.rs b/zed/src/editor/element.rs index 791c6a5be0..8ab6c52cc5 100644 --- a/zed/src/editor/element.rs +++ b/zed/src/editor/element.rs @@ -8,6 +8,7 @@ use gpui::{ PathBuilder, }, json::{self, ToJson}, + keymap::Keystroke, text_layout::{self, TextLayoutCache}, AppContext, Axis, Border, Element, Event, EventContext, FontCache, LayoutContext, MutableAppContext, PaintContext, Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle, @@ -127,14 +128,14 @@ impl EditorElement { } } - fn key_down(&self, chars: &str, cx: &mut EventContext) -> bool { + fn key_down(&self, chars: &str, keystroke: &Keystroke, cx: &mut EventContext) -> bool { let view = self.view.upgrade(cx.app).unwrap(); if view.is_focused(cx.app) { if chars.is_empty() { false } else { - if chars.chars().any(|c| c.is_control()) { + if chars.chars().any(|c| c.is_control()) || keystroke.cmd || keystroke.ctrl { false } else { cx.dispatch_action(Insert(chars.to_string())); @@ -629,7 +630,9 @@ impl Element for EditorElement { delta, precise, } => self.scroll(*position, *delta, *precise, layout, paint, cx), - Event::KeyDown { chars, .. } => self.key_down(chars, cx), + Event::KeyDown { + chars, keystroke, .. + } => self.key_down(chars, keystroke, cx), _ => false, } } else { diff --git a/zed/src/lib.rs b/zed/src/lib.rs index e7bb31b207..162c69c1db 100644 --- a/zed/src/lib.rs +++ b/zed/src/lib.rs @@ -22,7 +22,7 @@ pub mod worktree; use crate::util::TryFutureExt; use channel::ChannelList; -use gpui::{action, ModelHandle}; +use gpui::{action, keymap::Binding, ModelHandle}; use parking_lot::Mutex; use postage::watch; use std::sync::Arc; @@ -32,6 +32,9 @@ pub use settings::Settings; action!(About); action!(Quit); action!(Authenticate); +action!(AdjustBufferFontSize, f32); + +const MIN_FONT_SIZE: f32 = 6.0; pub struct AppState { pub settings_tx: Arc>>, @@ -54,6 +57,22 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { .detach(); } }); + + cx.add_global_action({ + let settings_tx = app_state.settings_tx.clone(); + + move |action: &AdjustBufferFontSize, cx| { + let mut settings_tx = settings_tx.lock(); + let new_size = (settings_tx.borrow().buffer_font_size + action.0).max(MIN_FONT_SIZE); + settings_tx.borrow_mut().buffer_font_size = new_size; + cx.refresh_windows(); + } + }); + + cx.add_bindings(vec![ + Binding::new("cmd-=", AdjustBufferFontSize(1.), None), + Binding::new("cmd--", AdjustBufferFontSize(-1.), None), + ]) } fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {