mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 21:32:40 +00:00
Add bindings to adjust buffer font size
This commit is contained in:
parent
bdf30f1a77
commit
fe3889c786
2 changed files with 26 additions and 4 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<Mutex<watch::Sender<Settings>>>,
|
||||
|
@ -54,6 +57,22 @@ pub fn init(app_state: &Arc<AppState>, 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) {
|
||||
|
|
Loading…
Reference in a new issue