Fix showing "enter Accept" for prediction with LSP menu open (#24218)
Release Notes: - N/A
This commit is contained in:
parent
3e68f7fde4
commit
b5d4b17f60
1 changed files with 38 additions and 20 deletions
|
@ -3276,10 +3276,7 @@ impl EditorElement {
|
|||
accept_keystroke = Some(Keystroke {
|
||||
modifiers: gpui::Modifiers {
|
||||
alt: true,
|
||||
control: false,
|
||||
shift: false,
|
||||
platform: false,
|
||||
function: false,
|
||||
..Default::default()
|
||||
},
|
||||
key: "tab".to_string(),
|
||||
key_char: None,
|
||||
|
@ -3291,10 +3288,7 @@ impl EditorElement {
|
|||
accept_keystroke = Some(Keystroke {
|
||||
modifiers: gpui::Modifiers {
|
||||
alt: true,
|
||||
control: false,
|
||||
shift: false,
|
||||
platform: false,
|
||||
function: false,
|
||||
..Default::default()
|
||||
},
|
||||
key: "enter".to_string(),
|
||||
key_char: None,
|
||||
|
@ -3687,12 +3681,13 @@ 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),
|
||||
true,
|
||||
previewing,
|
||||
self.editor.focus_handle(cx),
|
||||
window,
|
||||
cx,
|
||||
|
@ -3705,7 +3700,7 @@ impl EditorElement {
|
|||
let mut element = inline_completion_accept_indicator(
|
||||
"Jump to Edit",
|
||||
Some(IconName::ArrowDown),
|
||||
true,
|
||||
previewing,
|
||||
self.editor.focus_handle(cx),
|
||||
window,
|
||||
cx,
|
||||
|
@ -3721,7 +3716,7 @@ impl EditorElement {
|
|||
let mut element = inline_completion_accept_indicator(
|
||||
"Jump to Edit",
|
||||
None,
|
||||
true,
|
||||
previewing,
|
||||
self.editor.focus_handle(cx),
|
||||
window,
|
||||
cx,
|
||||
|
@ -3789,7 +3784,7 @@ impl EditorElement {
|
|||
let mut element = inline_completion_accept_indicator(
|
||||
"Accept",
|
||||
None,
|
||||
!previewing,
|
||||
previewing,
|
||||
self.editor.focus_handle(cx),
|
||||
window,
|
||||
cx,
|
||||
|
@ -5827,17 +5822,40 @@ fn header_jump_data(
|
|||
fn inline_completion_accept_indicator(
|
||||
label: impl Into<SharedString>,
|
||||
icon: Option<IconName>,
|
||||
show_modifiers: bool,
|
||||
previewing: bool,
|
||||
focus_handle: FocusHandle,
|
||||
window: &Window,
|
||||
cx: &App,
|
||||
) -> AnyElement {
|
||||
let bindings = window.bindings_for_action_in(&crate::AcceptInlineCompletion, &focus_handle);
|
||||
let Some(accept_keystroke) = bindings
|
||||
.last()
|
||||
.and_then(|binding| binding.keystrokes().first())
|
||||
else {
|
||||
return div().into_any();
|
||||
let use_hardcoded_linux_preview_binding;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use_hardcoded_linux_preview_binding = false;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
use_hardcoded_linux_preview_binding = previewing;
|
||||
}
|
||||
|
||||
let accept_keystroke = if use_hardcoded_linux_preview_binding {
|
||||
Keystroke {
|
||||
modifiers: Default::default(),
|
||||
key: "enter".to_string(),
|
||||
key_char: None,
|
||||
}
|
||||
} else {
|
||||
let bindings = window.bindings_for_action_in(&crate::AcceptInlineCompletion, &focus_handle);
|
||||
if let Some(keystroke) = bindings
|
||||
.last()
|
||||
.and_then(|binding| binding.keystrokes().first())
|
||||
{
|
||||
// TODO: clone unnecessary once `use_hardcoded_linux_preview_binding` is removed.
|
||||
keystroke.clone()
|
||||
} else {
|
||||
return div().into_any();
|
||||
}
|
||||
};
|
||||
|
||||
let accept_key = h_flex()
|
||||
|
@ -5846,7 +5864,7 @@ fn inline_completion_accept_indicator(
|
|||
.text_size(TextSize::XSmall.rems(cx))
|
||||
.text_color(cx.theme().colors().text)
|
||||
.gap_1()
|
||||
.when(show_modifiers, |parent| {
|
||||
.when(!previewing, |parent| {
|
||||
parent.children(ui::render_modifiers(
|
||||
&accept_keystroke.modifiers,
|
||||
PlatformStyle::platform(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue