edit predictions: Handle no keybind for preview (#25015)

If the user removes all modified keybinds in `edit_prediction_conflict`,
the preview bar above the completions menu would disappear. This PR
handles that case slightly better by still showing the 1-line preview
(which they might accept via an unmodified keybind) and hides the `|
Preview ⌥` section since it's impossible to invoke in this case.

Release Notes:

- Handle `edit_prediction_conflict` context without modified keybinds
for `AcceptEditPrediction`
This commit is contained in:
Agus Zubiaga 2025-02-17 16:00:20 -03:00 committed by GitHub
parent 08e9080ec9
commit 478bccadd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 32 deletions

View file

@ -5762,7 +5762,7 @@ impl Editor {
max_width: Pixels, max_width: Pixels,
cursor_point: Point, cursor_point: Point,
style: &EditorStyle, style: &EditorStyle,
accept_keystroke: &gpui::Keystroke, accept_keystroke: Option<&gpui::Keystroke>,
_window: &Window, _window: &Window,
cx: &mut Context<Editor>, cx: &mut Context<Editor>,
) -> Option<AnyElement> { ) -> Option<AnyElement> {
@ -5841,7 +5841,7 @@ impl Editor {
) )
.child(Label::new("Hold").size(LabelSize::Small)) .child(Label::new("Hold").size(LabelSize::Small))
.child(h_flex().children(ui::render_modifiers( .child(h_flex().children(ui::render_modifiers(
&accept_keystroke.modifiers, &accept_keystroke?.modifiers,
PlatformStyle::platform(), PlatformStyle::platform(),
Some(Color::Default), Some(Color::Default),
Some(IconSize::Small.rems().into()), Some(IconSize::Small.rems().into()),
@ -5906,7 +5906,12 @@ impl Editor {
.overflow_hidden() .overflow_hidden()
.child(completion), .child(completion),
) )
.child( .when_some(accept_keystroke, |el, accept_keystroke| {
if !accept_keystroke.modifiers.modified() {
return el;
}
el.child(
h_flex() h_flex()
.h_full() .h_full()
.border_l_1() .border_l_1()
@ -5935,6 +5940,7 @@ impl Editor {
.child(Label::new("Preview").into_any_element()) .child(Label::new("Preview").into_any_element())
.opacity(if has_completion { 1.0 } else { 0.4 }), .opacity(if has_completion { 1.0 } else { 0.4 }),
) )
})
.into_any(), .into_any(),
) )
} }

View file

@ -3255,7 +3255,7 @@ impl EditorElement {
max_width, max_width,
cursor_point, cursor_point,
style, style,
accept_binding.keystroke()?, accept_binding.keystroke(),
window, window,
cx, cx,
)?; )?;