Refactor KeybindingKeystroke (#37065)
This pull request refactors the `KeybindingKeystroke` struct and related code to improve platform abstraction. The changes centralize platform-specific logic within `KeybindingKeystroke` and update its usage throughout the codebase, making the API more consistent and less error-prone. Release Notes: - N/A
This commit is contained in:
+12
-12
@@ -2588,7 +2588,7 @@ impl Editor {
|
||||
|| binding
|
||||
.keystrokes()
|
||||
.first()
|
||||
.is_some_and(|keystroke| keystroke.display_modifiers.modified())
|
||||
.is_some_and(|keystroke| keystroke.modifiers().modified())
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -7686,16 +7686,16 @@ impl Editor {
|
||||
.keystroke()
|
||||
{
|
||||
modifiers_held = modifiers_held
|
||||
|| (&accept_keystroke.display_modifiers == modifiers
|
||||
&& accept_keystroke.display_modifiers.modified());
|
||||
|| (accept_keystroke.modifiers() == modifiers
|
||||
&& accept_keystroke.modifiers().modified());
|
||||
};
|
||||
if let Some(accept_partial_keystroke) = self
|
||||
.accept_edit_prediction_keybind(true, window, cx)
|
||||
.keystroke()
|
||||
{
|
||||
modifiers_held = modifiers_held
|
||||
|| (&accept_partial_keystroke.display_modifiers == modifiers
|
||||
&& accept_partial_keystroke.display_modifiers.modified());
|
||||
|| (accept_partial_keystroke.modifiers() == modifiers
|
||||
&& accept_partial_keystroke.modifiers().modified());
|
||||
}
|
||||
|
||||
if modifiers_held {
|
||||
@@ -9044,7 +9044,7 @@ impl Editor {
|
||||
|
||||
let is_platform_style_mac = PlatformStyle::platform() == PlatformStyle::Mac;
|
||||
|
||||
let modifiers_color = if accept_keystroke.display_modifiers == window.modifiers() {
|
||||
let modifiers_color = if *accept_keystroke.modifiers() == window.modifiers() {
|
||||
Color::Accent
|
||||
} else {
|
||||
Color::Muted
|
||||
@@ -9056,19 +9056,19 @@ impl Editor {
|
||||
.font(theme::ThemeSettings::get_global(cx).buffer_font.clone())
|
||||
.text_size(TextSize::XSmall.rems(cx))
|
||||
.child(h_flex().children(ui::render_modifiers(
|
||||
&accept_keystroke.display_modifiers,
|
||||
accept_keystroke.modifiers(),
|
||||
PlatformStyle::platform(),
|
||||
Some(modifiers_color),
|
||||
Some(IconSize::XSmall.rems().into()),
|
||||
true,
|
||||
)))
|
||||
.when(is_platform_style_mac, |parent| {
|
||||
parent.child(accept_keystroke.display_key.clone())
|
||||
parent.child(accept_keystroke.key().to_string())
|
||||
})
|
||||
.when(!is_platform_style_mac, |parent| {
|
||||
parent.child(
|
||||
Key::new(
|
||||
util::capitalize(&accept_keystroke.display_key),
|
||||
util::capitalize(accept_keystroke.key()),
|
||||
Some(Color::Default),
|
||||
)
|
||||
.size(Some(IconSize::XSmall.rems().into())),
|
||||
@@ -9249,7 +9249,7 @@ impl Editor {
|
||||
accept_keystroke.as_ref(),
|
||||
|el, accept_keystroke| {
|
||||
el.child(h_flex().children(ui::render_modifiers(
|
||||
&accept_keystroke.display_modifiers,
|
||||
accept_keystroke.modifiers(),
|
||||
PlatformStyle::platform(),
|
||||
Some(Color::Default),
|
||||
Some(IconSize::XSmall.rems().into()),
|
||||
@@ -9319,7 +9319,7 @@ impl Editor {
|
||||
.child(completion),
|
||||
)
|
||||
.when_some(accept_keystroke, |el, accept_keystroke| {
|
||||
if !accept_keystroke.display_modifiers.modified() {
|
||||
if !accept_keystroke.modifiers().modified() {
|
||||
return el;
|
||||
}
|
||||
|
||||
@@ -9338,7 +9338,7 @@ impl Editor {
|
||||
.font(theme::ThemeSettings::get_global(cx).buffer_font.clone())
|
||||
.when(is_platform_style_mac, |parent| parent.gap_1())
|
||||
.child(h_flex().children(ui::render_modifiers(
|
||||
&accept_keystroke.display_modifiers,
|
||||
accept_keystroke.modifiers(),
|
||||
PlatformStyle::platform(),
|
||||
Some(if !has_completion {
|
||||
Color::Muted
|
||||
|
||||
Reference in New Issue
Block a user