diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index fba395c906bdf04e390aabf0e9fd0b6a975d615f..233ac8bf7f263a1c31ca7b39dac254956e409310 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5606,10 +5606,10 @@ impl Editor { if provider.provider.needs_terms_acceptance(cx) { return Some( h_flex() - .h(self.edit_prediction_cursor_popover_height()) .min_w(min_width) .flex_1() .px_2() + .py_1() .gap_3() .elevation_2(cx) .hover(|style| style.bg(cx.theme().colors().element_hover)) @@ -5699,11 +5699,11 @@ impl Editor { Some( h_flex() - .h(self.edit_prediction_cursor_popover_height()) .min_w(min_width) .max_w(max_width) .flex_1() .px_2() + .py_1() .elevation_2(cx) .child(completion) .child(ui::Divider::vertical()) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index ecac1da5b430ca7944b45b33b512cfab367cae58..c6fd163a46e646ce6abf1c0f26c8fbfadf32f6be 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -3560,13 +3560,11 @@ impl EditorElement { match &active_inline_completion.completion { InlineCompletion::Move { target, .. } => { - let previewing = false; let target_display_point = target.to_display_point(editor_snapshot); if target_display_point.row().as_f32() < scroll_top { let mut element = inline_completion_accept_indicator( "Jump to Edit", Some(IconName::ArrowUp), - previewing, editor, window, cx, @@ -3579,7 +3577,6 @@ impl EditorElement { let mut element = inline_completion_accept_indicator( "Jump to Edit", Some(IconName::ArrowDown), - previewing, editor, window, cx, @@ -3595,7 +3592,6 @@ impl EditorElement { let mut element = inline_completion_accept_indicator( "Jump to Edit", None, - previewing, editor, window, cx, @@ -3658,12 +3654,7 @@ impl EditorElement { let (mut element, origin) = self.editor.update(cx, |editor, cx| { Some(( inline_completion_accept_indicator( - "Accept", - None, - editor.previewing_inline_completion, - editor, - window, - cx, + "Accept", None, editor, window, cx, )?, editor.display_to_pixel_point( target_line_end, @@ -5669,7 +5660,6 @@ fn header_jump_data( fn inline_completion_accept_indicator( label: impl Into, icon: Option, - previewing: bool, editor: &Editor, window: &mut Window, cx: &App, @@ -5683,7 +5673,7 @@ fn inline_completion_accept_indicator( .text_size(TextSize::XSmall.rems(cx)) .text_color(cx.theme().colors().text) .gap_1() - .when(!previewing, |parent| { + .when(!editor.previewing_inline_completion, |parent| { parent.children(ui::render_modifiers( &accept_keystroke.modifiers, PlatformStyle::platform(), diff --git a/crates/gpui/src/geometry.rs b/crates/gpui/src/geometry.rs index d6cd83ae605afa448c153649ed197823ecda5f2a..ce3f9bde0d75f3d1f6cdc74724d373ef06fc19ef 100644 --- a/crates/gpui/src/geometry.rs +++ b/crates/gpui/src/geometry.rs @@ -2975,6 +2975,22 @@ impl AbsoluteLength { AbsoluteLength::Rems(rems) => rems.to_pixels(rem_size), } } + + /// Converts an `AbsoluteLength` to `Rems` based on a given `rem_size`. + /// + /// # Arguments + /// + /// * `rem_size` - The size of one rem in pixels. + /// + /// # Returns + /// + /// Returns the `AbsoluteLength` as `Pixels`. + pub fn to_rems(&self, rem_size: Pixels) -> Rems { + match self { + AbsoluteLength::Pixels(pixels) => Rems(pixels.0 / rem_size.0), + AbsoluteLength::Rems(rems) => *rems, + } + } } impl Default for AbsoluteLength { diff --git a/crates/ui/src/components/icon.rs b/crates/ui/src/components/icon.rs index c23c41cbcf7119b2c368857b8ffe953c6f445b3d..3b1f225d3f081efc1be2899c532a81f249823e58 100644 --- a/crates/ui/src/components/icon.rs +++ b/crates/ui/src/components/icon.rs @@ -66,7 +66,7 @@ pub enum IconSize { Medium, /// 48px XLarge, - Custom(Pixels), + Custom(Rems), } impl IconSize { @@ -77,7 +77,7 @@ impl IconSize { IconSize::Small => rems_from_px(14.), IconSize::Medium => rems_from_px(16.), IconSize::XLarge => rems_from_px(48.), - IconSize::Custom(size) => rems_from_px(size.into()), + IconSize::Custom(size) => size, } } @@ -95,7 +95,7 @@ impl IconSize { IconSize::Medium => DynamicSpacing::Base02.px(cx), IconSize::XLarge => DynamicSpacing::Base02.px(cx), // TODO: Wire into dynamic spacing - IconSize::Custom(size) => px(size.into()), + IconSize::Custom(size) => size.to_pixels(window.rem_size()), }; (icon_size, padding) diff --git a/crates/ui/src/components/keybinding.rs b/crates/ui/src/components/keybinding.rs index c488e7999b00102cfca08e18eb5bb83deacc2c03..4391c9061bae5dc2fb47d47618f60010ab187414 100644 --- a/crates/ui/src/components/keybinding.rs +++ b/crates/ui/src/components/keybinding.rs @@ -15,7 +15,7 @@ pub struct KeyBinding { /// The [`PlatformStyle`] to use when displaying this keybinding. platform_style: PlatformStyle, - size: Option, + size: Option, } impl KeyBinding { @@ -59,8 +59,8 @@ impl KeyBinding { } /// Sets the size for this [`KeyBinding`]. - pub fn size(mut self, size: Pixels) -> Self { - self.size = Some(size); + pub fn size(mut self, size: impl Into) -> Self { + self.size = Some(size.into()); self } } @@ -105,7 +105,7 @@ pub fn render_key( keystroke: &Keystroke, platform_style: PlatformStyle, color: Option, - size: Option, + size: Option, ) -> AnyElement { let key_icon = icon_for_key(keystroke, platform_style); match key_icon { @@ -144,7 +144,7 @@ pub fn render_modifiers( modifiers: &Modifiers, platform_style: PlatformStyle, color: Option, - size: Option, + size: Option, standalone: bool, ) -> impl Iterator { enum KeyOrIcon { @@ -224,14 +224,13 @@ pub fn render_modifiers( pub struct Key { key: SharedString, color: Option, - size: Option, + size: Option, } impl RenderOnce for Key { fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement { let single_char = self.key.len() == 1; - let size = self.size.unwrap_or(px(14.)); - let size_f32: f32 = size.into(); + let size = self.size.unwrap_or(px(14.).into()); div() .py_0() @@ -242,7 +241,7 @@ impl RenderOnce for Key { this.px_0p5() } }) - .h(rems_from_px(size_f32)) + .h(size) .text_size(size) .line_height(relative(1.)) .text_color(self.color.unwrap_or(Color::Muted).color(cx)) @@ -259,7 +258,7 @@ impl Key { } } - pub fn size(mut self, size: impl Into>) -> Self { + pub fn size(mut self, size: impl Into>) -> Self { self.size = size.into(); self } @@ -269,17 +268,15 @@ impl Key { pub struct KeyIcon { icon: IconName, color: Option, - size: Option, + size: Option, } impl RenderOnce for KeyIcon { fn render(self, window: &mut Window, _cx: &mut App) -> impl IntoElement { - let size = self - .size - .unwrap_or(IconSize::Small.rems().to_pixels(window.rem_size())); + let size = self.size.unwrap_or(IconSize::Small.rems().into()); Icon::new(self.icon) - .size(IconSize::Custom(size)) + .size(IconSize::Custom(size.to_rems(window.rem_size()))) .color(self.color.unwrap_or(Color::Muted)) } } @@ -293,7 +290,7 @@ impl KeyIcon { } } - pub fn size(mut self, size: impl Into>) -> Self { + pub fn size(mut self, size: impl Into>) -> Self { self.size = size.into(); self } diff --git a/crates/ui/src/components/keybinding_hint.rs b/crates/ui/src/components/keybinding_hint.rs index 2abb93ea40b890568a6b4aa9517a800c8fd72035..b10e541ba504ae8550ed9e00323bd71b4f88861e 100644 --- a/crates/ui/src/components/keybinding_hint.rs +++ b/crates/ui/src/components/keybinding_hint.rs @@ -199,7 +199,7 @@ impl RenderOnce for KeybindingHint { blur_radius: px(0.), spread_radius: px(0.), }]) - .child(self.keybinding.size(kb_size)), + .child(self.keybinding.size(rems_from_px(kb_size.0))), ) .children(self.suffix) }