agent: Introduce agent_buffer_font_size setting (#39468)
Closes https://github.com/zed-industries/zed/issues/39406 Follow up to https://github.com/zed-industries/zed/pull/38726 This PR introduces the `agent_buffer_font_size` setting and renames `agent_font_size` to `agent_ui_font_size`. This allows whoever wants `buffer_font_size` and `agent_buffer_font_size` to match, as well as folks who want a slightly smaller size only in the agent panel (which... also looks just better by default!). Release Notes: - agent: Introduced the `agent_buffer_font_size` setting and renamed `agent_font_size` to `agent_ui_font_size`, allowing for granular buffer font size control in the agent panel vs. regular editors.
This commit is contained in:
@@ -115,7 +115,9 @@ pub struct ThemeSettings {
|
||||
/// The terminal font family can be overridden using it's own setting.
|
||||
pub buffer_font: Font,
|
||||
/// The agent font size. Determines the size of text in the agent panel. Falls back to the UI font size if unset.
|
||||
agent_font_size: Option<Pixels>,
|
||||
agent_ui_font_size: Option<Pixels>,
|
||||
/// The agent buffer font size. Determines the size of user messages in the agent panel. Falls back to the buffer font size if unset.
|
||||
agent_buffer_font_size: Option<Pixels>,
|
||||
/// The line height for buffers, and the terminal.
|
||||
///
|
||||
/// Changing this may affect the spacing of some UI elements.
|
||||
@@ -539,14 +541,23 @@ impl ThemeSettings {
|
||||
}
|
||||
|
||||
/// Returns the agent panel font size. Falls back to the UI font size if unset.
|
||||
pub fn agent_font_size(&self, cx: &App) -> Pixels {
|
||||
pub fn agent_ui_font_size(&self, cx: &App) -> Pixels {
|
||||
cx.try_global::<AgentFontSize>()
|
||||
.map(|size| size.0)
|
||||
.or(self.agent_font_size)
|
||||
.or(self.agent_ui_font_size)
|
||||
.map(clamp_font_size)
|
||||
.unwrap_or_else(|| self.ui_font_size(cx))
|
||||
}
|
||||
|
||||
/// Returns the agent panel buffer font size. Falls back to the buffer font size if unset.
|
||||
pub fn agent_buffer_font_size(&self, cx: &App) -> Pixels {
|
||||
cx.try_global::<AgentFontSize>()
|
||||
.map(|size| size.0)
|
||||
.or(self.agent_buffer_font_size)
|
||||
.map(clamp_font_size)
|
||||
.unwrap_or_else(|| self.buffer_font_size(cx))
|
||||
}
|
||||
|
||||
/// Returns the buffer font size, read from the settings.
|
||||
///
|
||||
/// The real buffer font size is stored in-memory, to support temporary font size changes.
|
||||
@@ -566,9 +577,17 @@ impl ThemeSettings {
|
||||
/// Returns the agent font size, read from the settings.
|
||||
///
|
||||
/// The real agent font size is stored in-memory, to support temporary font size changes.
|
||||
/// Use [`Self::agent_font_size`] to get the real font size.
|
||||
pub fn agent_font_size_settings(&self) -> Option<Pixels> {
|
||||
self.agent_font_size
|
||||
/// Use [`Self::agent_ui_font_size`] to get the real font size.
|
||||
pub fn agent_ui_font_size_settings(&self) -> Option<Pixels> {
|
||||
self.agent_ui_font_size
|
||||
}
|
||||
|
||||
/// Returns the agent buffer font size, read from the settings.
|
||||
///
|
||||
/// The real agent buffer font size is stored in-memory, to support temporary font size changes.
|
||||
/// Use [`Self::agent_buffer_font_size`] to get the real font size.
|
||||
pub fn agent_buffer_font_size_settings(&self) -> Option<Pixels> {
|
||||
self.agent_buffer_font_size
|
||||
}
|
||||
|
||||
// TODO: Rename: `line_height` -> `buffer_line_height`
|
||||
@@ -725,18 +744,36 @@ pub fn reset_ui_font_size(cx: &mut App) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the adjusted agent panel font size.
|
||||
pub fn adjust_agent_font_size(cx: &mut App, f: impl FnOnce(Pixels) -> Pixels) {
|
||||
let agent_font_size = ThemeSettings::get_global(cx).agent_font_size(cx);
|
||||
/// Sets the adjusted font size of agent responses in the agent panel.
|
||||
pub fn adjust_agent_ui_font_size(cx: &mut App, f: impl FnOnce(Pixels) -> Pixels) {
|
||||
let agent_ui_font_size = ThemeSettings::get_global(cx).agent_ui_font_size(cx);
|
||||
let adjusted_size = cx
|
||||
.try_global::<AgentFontSize>()
|
||||
.map_or(agent_font_size, |adjusted_size| adjusted_size.0);
|
||||
.map_or(agent_ui_font_size, |adjusted_size| adjusted_size.0);
|
||||
cx.set_global(AgentFontSize(clamp_font_size(f(adjusted_size))));
|
||||
cx.refresh_windows();
|
||||
}
|
||||
|
||||
/// Resets the agent panel font size to the default value.
|
||||
pub fn reset_agent_font_size(cx: &mut App) {
|
||||
/// Resets the agent response font size in the agent panel to the default value.
|
||||
pub fn reset_agent_ui_font_size(cx: &mut App) {
|
||||
if cx.has_global::<AgentFontSize>() {
|
||||
cx.remove_global::<AgentFontSize>();
|
||||
cx.refresh_windows();
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the adjusted font size of user messages in the agent panel.
|
||||
pub fn adjust_agent_buffer_font_size(cx: &mut App, f: impl FnOnce(Pixels) -> Pixels) {
|
||||
let agent_buffer_font_size = ThemeSettings::get_global(cx).agent_buffer_font_size(cx);
|
||||
let adjusted_size = cx
|
||||
.try_global::<AgentFontSize>()
|
||||
.map_or(agent_buffer_font_size, |adjusted_size| adjusted_size.0);
|
||||
cx.set_global(AgentFontSize(clamp_font_size(f(adjusted_size))));
|
||||
cx.refresh_windows();
|
||||
}
|
||||
|
||||
/// Resets the user message font size in the agent panel to the default value.
|
||||
pub fn reset_agent_buffer_font_size(cx: &mut App) {
|
||||
if cx.has_global::<AgentFontSize>() {
|
||||
cx.remove_global::<AgentFontSize>();
|
||||
cx.refresh_windows();
|
||||
@@ -798,7 +835,8 @@ impl settings::Settings for ThemeSettings {
|
||||
},
|
||||
buffer_font_size: clamp_font_size(content.buffer_font_size.unwrap().into()),
|
||||
buffer_line_height: content.buffer_line_height.unwrap().into(),
|
||||
agent_font_size: content.agent_font_size.map(Into::into),
|
||||
agent_ui_font_size: content.agent_ui_font_size.map(Into::into),
|
||||
agent_buffer_font_size: content.agent_buffer_font_size.map(Into::into),
|
||||
active_theme: themes
|
||||
.get(theme_selection.theme(*system_appearance))
|
||||
.or(themes.get(&zed_default_dark().name))
|
||||
|
||||
@@ -111,8 +111,11 @@ pub fn init(themes_to_load: LoadThemes, cx: &mut App) {
|
||||
let mut prev_buffer_font_size_settings =
|
||||
ThemeSettings::get_global(cx).buffer_font_size_settings();
|
||||
let mut prev_ui_font_size_settings = ThemeSettings::get_global(cx).ui_font_size_settings();
|
||||
let mut prev_agent_font_size_settings =
|
||||
ThemeSettings::get_global(cx).agent_font_size_settings();
|
||||
let mut prev_agent_ui_font_size_settings =
|
||||
ThemeSettings::get_global(cx).agent_ui_font_size_settings();
|
||||
let mut prev_agent_buffer_font_size_settings =
|
||||
ThemeSettings::get_global(cx).agent_buffer_font_size_settings();
|
||||
|
||||
cx.observe_global::<SettingsStore>(move |cx| {
|
||||
let buffer_font_size_settings = ThemeSettings::get_global(cx).buffer_font_size_settings();
|
||||
if buffer_font_size_settings != prev_buffer_font_size_settings {
|
||||
@@ -126,10 +129,18 @@ pub fn init(themes_to_load: LoadThemes, cx: &mut App) {
|
||||
reset_ui_font_size(cx);
|
||||
}
|
||||
|
||||
let agent_font_size_settings = ThemeSettings::get_global(cx).agent_font_size_settings();
|
||||
if agent_font_size_settings != prev_agent_font_size_settings {
|
||||
prev_agent_font_size_settings = agent_font_size_settings;
|
||||
reset_agent_font_size(cx);
|
||||
let agent_ui_font_size_settings =
|
||||
ThemeSettings::get_global(cx).agent_ui_font_size_settings();
|
||||
if agent_ui_font_size_settings != prev_agent_ui_font_size_settings {
|
||||
prev_agent_ui_font_size_settings = agent_ui_font_size_settings;
|
||||
reset_agent_ui_font_size(cx);
|
||||
}
|
||||
|
||||
let agent_buffer_font_size_settings =
|
||||
ThemeSettings::get_global(cx).agent_buffer_font_size_settings();
|
||||
if agent_buffer_font_size_settings != prev_agent_buffer_font_size_settings {
|
||||
prev_agent_buffer_font_size_settings = agent_buffer_font_size_settings;
|
||||
reset_agent_buffer_font_size(cx);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
Reference in New Issue
Block a user