Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions crates/editor/src/element/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ use std::time::{Duration, Instant};
use collections::HashMap;
use feature_flags::{DiffReviewFeatureFlag, FeatureFlagAppExt as _};
use gpui::{
AnyElement, App, AvailableSpace, ClickEvent, Context, DefiniteLength, DispatchPhase, Element,
MouseButton, MouseClickEvent, MouseDownEvent, MouseMoveEvent, MousePressureEvent, MouseUpEvent,
ParentElement, Pixels, PressureStage, ScrollDelta, ScrollWheelEvent, TextStyleRefinement,
Window, anchored, deferred, point, px,
AnyElement, App, AvailableSpace, ClickEvent, Context, DispatchPhase, Element, MouseButton,
MouseClickEvent, MouseDownEvent, MouseMoveEvent, MousePressureEvent, MouseUpEvent,
ParentElement, Pixels, PressureStage, ScrollDelta, ScrollWheelEvent, Window, anchored,
deferred, point, px,
};
use multi_buffer::MultiBufferRow;
use project::DisableAiSettings;
use settings::Settings;
use sum_tree::Bias;
use text::SelectionGoal;
use theme_settings::BufferLineHeight;
use util::{RangeExt, debug_panic, post_inc};

use super::{EditorElement, EditorLayout, LineNumberLayout, PositionMap, SplitSide};
Expand Down Expand Up @@ -322,33 +321,25 @@ impl EditorElement {
}
})?;

let text_style = TextStyleRefinement {
line_height: Some(DefiniteLength::Fraction(
BufferLineHeight::Comfortable.value(),
)),
..Default::default()
};
window.with_text_style(Some(text_style), |window| {
let mut element = self.editor.read_with(cx, |editor, _| {
let mouse_context_menu = editor.mouse_context_menu.as_ref()?;
let context_menu = mouse_context_menu.context_menu.clone();

Some(
deferred(
anchored()
.position(position)
.child(context_menu)
.anchor(gpui::Anchor::TopLeft)
.snap_to_window_with_margin(px(8.)),
)
.with_priority(1)
.into_any(),
let mut element = self.editor.read_with(cx, |editor, _| {
let mouse_context_menu = editor.mouse_context_menu.as_ref()?;
let context_menu = mouse_context_menu.context_menu.clone();

Some(
deferred(
anchored()
.position(position)
.child(context_menu)
.anchor(gpui::Anchor::TopLeft)
.snap_to_window_with_margin(px(8.)),
)
})?;
.with_priority(1)
.into_any(),
)
})?;

element.prepaint_as_root(position, AvailableSpace::min_size(), window, cx);
Some(element)
})
element.prepaint_as_root(position, AvailableSpace::min_size(), window, cx);
Some(element)
}

pub(super) fn paint_mouse_listeners(
Expand Down
6 changes: 4 additions & 2 deletions crates/settings_ui/src/page_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,10 @@ fn appearance_page() -> SettingsPage {
}
settings::BufferLineHeightDiscriminants::Custom => {
let custom_value =
theme_settings::BufferLineHeight::from(*settings_value)
.value();
theme_settings::buffer_line_height_from_settings(
*settings_value,
)
.value();
settings::BufferLineHeight::Custom(custom_value)
}
};
Expand Down
22 changes: 22 additions & 0 deletions crates/theme/src/buffer_line_height.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// The buffer's line height.
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub enum BufferLineHeight {
/// A less dense line height.
#[default]
Comfortable,
/// The default line height.
Standard,
/// A custom line height, where 1.0 is the font's height. Must be at least 1.0.
Custom(f32),
}

impl BufferLineHeight {
/// Returns the value of the line height.
pub fn value(&self) -> f32 {
match self {
BufferLineHeight::Comfortable => 1.618,
BufferLineHeight::Standard => 1.3,
BufferLineHeight::Custom(line_height) => *line_height,
}
}
}
2 changes: 2 additions & 0 deletions crates/theme/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//!
//! A theme is a collection of colors used to build a consistent appearance for UI components across the application.

mod buffer_line_height;
mod color_space;
mod default_colors;
mod fallback_themes;
Expand All @@ -31,6 +32,7 @@ use gpui::{
};
use serde::Deserialize;

pub use crate::buffer_line_height::*;
pub use crate::color_space::*;
pub use crate::default_colors::*;
pub use crate::fallback_themes::{apply_status_color_defaults, apply_theme_color_defaults};
Expand Down
41 changes: 9 additions & 32 deletions crates/theme_settings/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,38 +359,13 @@ pub fn set_mode(content: &mut SettingsContent, mode: ThemeAppearanceMode) {
}
}

/// The buffer's line height.
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub enum BufferLineHeight {
/// A less dense line height.
#[default]
Comfortable,
/// The default line height.
Standard,
/// A custom line height, where 1.0 is the font's height. Must be at least 1.0.
Custom(f32),
}

impl From<settings::BufferLineHeight> for BufferLineHeight {
fn from(value: settings::BufferLineHeight) -> Self {
match value {
settings::BufferLineHeight::Comfortable => BufferLineHeight::Comfortable,
settings::BufferLineHeight::Standard => BufferLineHeight::Standard,
settings::BufferLineHeight::Custom(line_height) => {
BufferLineHeight::Custom(line_height)
}
}
}
}
pub use theme::BufferLineHeight;

impl BufferLineHeight {
/// Returns the value of the line height.
pub fn value(&self) -> f32 {
match self {
BufferLineHeight::Comfortable => 1.618,
BufferLineHeight::Standard => 1.3,
BufferLineHeight::Custom(line_height) => *line_height,
}
pub fn buffer_line_height_from_settings(value: settings::BufferLineHeight) -> BufferLineHeight {
match value {
settings::BufferLineHeight::Comfortable => BufferLineHeight::Comfortable,
settings::BufferLineHeight::Standard => BufferLineHeight::Standard,
settings::BufferLineHeight::Custom(line_height) => BufferLineHeight::Custom(line_height),
}
}

Expand Down Expand Up @@ -754,7 +729,9 @@ impl settings::Settings for ThemeSettings {
style: FontStyle::default(),
},
buffer_font_size: clamp_font_size(content.buffer_font_size.unwrap().into_gpui()),
buffer_line_height: content.buffer_line_height.unwrap().into(),
buffer_line_height: buffer_line_height_from_settings(
content.buffer_line_height.unwrap(),
),
agent_ui_font_family: content
.agent_ui_font_family
.as_ref()
Expand Down
8 changes: 4 additions & 4 deletions crates/theme_settings/src/theme_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub use crate::settings::{
ThemeAppearanceMode, ThemeName, ThemeSelection, ThemeSettings, adjust_agent_buffer_font_size,
adjust_agent_ui_font_size, adjust_git_commit_buffer_font_size,
adjust_markdown_preview_font_size, adjust_ui_font_size, adjusted_font_size, appearance_to_mode,
clamp_font_size, default_theme, observe_buffer_font_size_adjustment,
reset_agent_buffer_font_size, reset_agent_ui_font_size, reset_buffer_font_size,
reset_git_commit_buffer_font_size, reset_markdown_preview_font_size, reset_ui_font_size,
set_icon_theme, set_mode, set_theme, setup_ui_font,
buffer_line_height_from_settings, clamp_font_size, default_theme,
observe_buffer_font_size_adjustment, reset_agent_buffer_font_size, reset_agent_ui_font_size,
reset_buffer_font_size, reset_git_commit_buffer_font_size, reset_markdown_preview_font_size,
reset_ui_font_size, set_icon_theme, set_mode, set_theme, setup_ui_font,
};
pub use theme::UiDensity;

Expand Down
9 changes: 8 additions & 1 deletion crates/ui/src/components/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use gpui::{
Action, Anchor, AnyElement, App, Bounds, DismissEvent, Entity, EventEmitter, FocusHandle,
Focusable, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels, Point, Role,
Size, Subscription, TaskExt, anchored, canvas, prelude::*, px,
Size, Subscription, TaskExt, anchored, canvas, prelude::*, px, relative,
};
use menu::{SelectChild, SelectFirst, SelectLast, SelectNext, SelectParent, SelectPrevious};
use std::{
Expand All @@ -14,6 +14,7 @@ use std::{
rc::Rc,
time::{Duration, Instant},
};
use theme::BufferLineHeight;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum SubmenuOpenTrigger {
Expand Down Expand Up @@ -2194,6 +2195,10 @@ impl Render for ContextMenu {
let theme_settings = theme::theme_settings(cx);
let ui_font_size = theme_settings.ui_font_size(cx);
let ui_font_family = theme_settings.ui_font(cx).family.clone();
// Menus can be deferred from inside elements that override the text
// style (e.g. the editor with a custom `buffer_line_height`), so always
// apply the default line height to render the same everywhere.
let line_height = relative(BufferLineHeight::Comfortable.value());
let window_size = window.viewport_size();
let rem_size = window.rem_size();
let is_wide_window = window_size.width / rem_size > rems_from_px(800.).0;
Expand Down Expand Up @@ -2244,6 +2249,7 @@ impl Render for ContextMenu {
WithRemSize::new(ui_font_size)
.occlude()
.font_family(ui_font_family.clone())
.line_height(line_height)
.elevation_2(cx)
.w_full()
.p_2()
Expand Down Expand Up @@ -2271,6 +2277,7 @@ impl Render for ContextMenu {
WithRemSize::new(ui_font_size)
.occlude()
.font_family(ui_font_family.clone())
.line_height(line_height)
.elevation_2(cx)
.flex()
.flex_row()
Expand Down
Loading