From f8c436fe7fe828c2c17dcd3302e35f78075273d7 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Tue, 4 Feb 2025 12:32:30 -0700 Subject: [PATCH] Fix prediction preview binding: `Alt + Preview` -> `Alt Preview` (#24220) Release Notes: - N/A --- crates/editor/src/editor.rs | 28 +++++++++++++------------- crates/editor/src/element.rs | 1 + crates/ui/src/components/keybinding.rs | 27 ++++++++++++++++--------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 3f624e2ddb..2d22bfcdd2 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5511,6 +5511,11 @@ impl Editor { let has_completion = self.active_inline_completion.is_some(); + let is_move = self + .active_inline_completion + .as_ref() + .map_or(false, |c| c.is_move()); + Some( h_flex() .h(self.edit_prediction_cursor_popover_height()) @@ -5539,23 +5544,18 @@ impl Editor { } else { None }, + !is_move, )), ) .opacity(if has_completion { 1.0 } else { 0.1 }) - .child( - if self - .active_inline_completion - .as_ref() - .map_or(false, |c| c.is_move()) - { - div() - .child(ui::Key::new(&accept_keystroke.key, None)) - .font(buffer_font.clone()) - .into_any() - } else { - Label::new("Preview").color(Color::Muted).into_any_element() - }, - ), + .child(if is_move { + div() + .child(ui::Key::new(&accept_keystroke.key, None)) + .font(buffer_font.clone()) + .into_any() + } else { + Label::new("Preview").color(Color::Muted).into_any_element() + }), ) .into_any(), ) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 78bcc86042..4b57f86544 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -5869,6 +5869,7 @@ fn inline_completion_accept_indicator( &accept_keystroke.modifiers, PlatformStyle::platform(), Some(Color::Default), + false, )) }) .child(accept_keystroke.key.clone()); diff --git a/crates/ui/src/components/keybinding.rs b/crates/ui/src/components/keybinding.rs index ebe7c14d5e..c78fe1524f 100644 --- a/crates/ui/src/components/keybinding.rs +++ b/crates/ui/src/components/keybinding.rs @@ -83,6 +83,7 @@ impl RenderOnce for KeyBinding { &keystroke.modifiers, self.platform_style, None, + false, )) .map(|el| el.child(render_key(&keystroke, self.platform_style, None))) })) @@ -129,6 +130,7 @@ pub fn render_modifiers( modifiers: &Modifiers, platform_style: PlatformStyle, color: Option, + standalone: bool, ) -> impl Iterator { enum KeyOrIcon { Key(&'static str), @@ -179,18 +181,23 @@ pub fn render_modifiers( ] }; - table + let filtered = table .into_iter() - .flat_map(move |modifier| { - if modifier.enabled { - match platform_style { - PlatformStyle::Mac => vec![modifier.mac], - PlatformStyle::Linux => vec![modifier.linux, KeyOrIcon::Key("+")], - PlatformStyle::Windows => vec![modifier.windows, KeyOrIcon::Key("+")], - } - } else { - vec![] + .filter(|modifier| modifier.enabled) + .collect::>(); + let last_ix = filtered.len().saturating_sub(1); + + filtered + .into_iter() + .enumerate() + .flat_map(move |(ix, modifier)| match platform_style { + PlatformStyle::Mac => vec![modifier.mac], + PlatformStyle::Linux if standalone && ix == last_ix => vec![modifier.linux], + PlatformStyle::Linux => vec![modifier.linux, KeyOrIcon::Key("+")], + PlatformStyle::Windows if standalone && ix == last_ix => { + vec![modifier.windows] } + PlatformStyle::Windows => vec![modifier.windows, KeyOrIcon::Key("+")], }) .map(move |key_or_icon| match key_or_icon { KeyOrIcon::Key(key) => Key::new(key, color).into_any_element(),