edit predictions: Add binding to the prediction toggle (#24468)

This PR primary goal is to add a keybinding to the (ephemeral)
prediction toggle. In doing that, we also standardized the keybinding to
open the status bar menu with it.

Release Notes:

- N/A

---------

Co-authored-by: Bennet Bo Fenner <53836821+bennetbo@users.noreply.github.com>
This commit is contained in:
Danilo Leal 2025-02-07 18:01:39 -03:00 committed by GitHub
parent 07f1b612cf
commit c4bcff1e87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 215 additions and 162 deletions

View file

@ -213,6 +213,7 @@ impl Render for QuickActionBar {
})
});
let editor_focus_handle = editor.focus_handle(cx);
let editor = editor.downgrade();
let editor_settings_dropdown = {
let vim_mode_enabled = VimModeSetting::get_global(cx).0;
@ -231,20 +232,67 @@ impl Render for QuickActionBar {
.anchor(Corner::TopRight)
.with_handle(self.toggle_settings_handle.clone())
.menu(move |window, cx| {
let menu = ContextMenu::build(window, cx, |mut menu, _, _| {
if supports_inlay_hints {
let menu = ContextMenu::build(window, cx, {
let focus_handle = editor_focus_handle.clone();
|mut menu, _, _| {
menu = menu.context(focus_handle);
if supports_inlay_hints {
menu = menu.toggleable_entry(
"Inlay Hints",
inlay_hints_enabled,
IconPosition::Start,
Some(editor::actions::ToggleInlayHints.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_inlay_hints(
&editor::actions::ToggleInlayHints,
window,
cx,
);
})
.ok();
}
},
);
}
menu = menu.toggleable_entry(
"Inlay Hints",
inlay_hints_enabled,
"Selection Menu",
selection_menu_enabled,
IconPosition::Start,
Some(editor::actions::ToggleInlayHints.boxed_clone()),
Some(editor::actions::ToggleSelectionMenu.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_inlay_hints(
&editor::actions::ToggleInlayHints,
editor.toggle_selection_menu(
&editor::actions::ToggleSelectionMenu,
window,
cx,
)
})
.ok();
}
},
);
menu = menu.toggleable_entry(
"Auto Signature Help",
auto_signature_help_enabled,
IconPosition::Start,
Some(editor::actions::ToggleAutoSignatureHelp.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_auto_signature_help_menu(
&editor::actions::ToggleAutoSignatureHelp,
window,
cx,
);
@ -253,138 +301,96 @@ impl Render for QuickActionBar {
}
},
);
let mut inline_completion_entry = ContextMenuEntry::new("Edit Predictions")
.toggleable(IconPosition::Start, inline_completion_enabled && show_inline_completions)
.disabled(!inline_completion_enabled)
.action(Some(
editor::actions::ToggleEditPrediction.boxed_clone(),
)).handler({
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_inline_completions(
&editor::actions::ToggleEditPrediction,
window,
cx,
);
})
.ok();
}
});
if !inline_completion_enabled {
inline_completion_entry = inline_completion_entry.documentation_aside(|_| {
Label::new("You can't toggle edit predictions for this file as it is within the excluded files list.").into_any_element()
});
}
menu = menu.item(inline_completion_entry);
menu = menu.separator();
menu = menu.toggleable_entry(
"Inline Git Blame",
git_blame_inline_enabled,
IconPosition::Start,
Some(editor::actions::ToggleGitBlameInline.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_git_blame_inline(
&editor::actions::ToggleGitBlameInline,
window,
cx,
)
})
.ok();
}
},
);
menu = menu.toggleable_entry(
"Column Git Blame",
show_git_blame_gutter,
IconPosition::Start,
Some(editor::actions::ToggleGitBlame.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_git_blame(
&editor::actions::ToggleGitBlame,
window,
cx,
)
})
.ok();
}
},
);
menu = menu.separator();
menu = menu.toggleable_entry(
"Vim Mode",
vim_mode_enabled,
IconPosition::Start,
None,
{
move |window, cx| {
let new_value = !vim_mode_enabled;
VimModeSetting::override_global(VimModeSetting(new_value), cx);
window.refresh();
}
},
);
menu
}
menu = menu.toggleable_entry(
"Selection Menu",
selection_menu_enabled,
IconPosition::Start,
Some(editor::actions::ToggleSelectionMenu.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_selection_menu(
&editor::actions::ToggleSelectionMenu,
window,
cx,
)
})
.ok();
}
},
);
menu = menu.toggleable_entry(
"Auto Signature Help",
auto_signature_help_enabled,
IconPosition::Start,
Some(editor::actions::ToggleAutoSignatureHelp.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_auto_signature_help_menu(
&editor::actions::ToggleAutoSignatureHelp,
window,
cx,
);
})
.ok();
}
},
);
let mut inline_completion_entry = ContextMenuEntry::new("Edit Predictions")
.toggleable(IconPosition::Start, inline_completion_enabled && show_inline_completions)
.disabled(!inline_completion_enabled)
.action(Some(
editor::actions::ToggleEditPrediction.boxed_clone(),
)).handler({
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_inline_completions(
&editor::actions::ToggleEditPrediction,
window,
cx,
);
})
.ok();
}
});
if !inline_completion_enabled {
inline_completion_entry = inline_completion_entry.documentation_aside(|_| {
Label::new("You can't toggle edit predictions for this file as it is within the excluded files list.").into_any_element()
});
}
menu = menu.item(inline_completion_entry);
menu = menu.separator();
menu = menu.toggleable_entry(
"Inline Git Blame",
git_blame_inline_enabled,
IconPosition::Start,
Some(editor::actions::ToggleGitBlameInline.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_git_blame_inline(
&editor::actions::ToggleGitBlameInline,
window,
cx,
)
})
.ok();
}
},
);
menu = menu.toggleable_entry(
"Column Git Blame",
show_git_blame_gutter,
IconPosition::Start,
Some(editor::actions::ToggleGitBlame.boxed_clone()),
{
let editor = editor.clone();
move |window, cx| {
editor
.update(cx, |editor, cx| {
editor.toggle_git_blame(
&editor::actions::ToggleGitBlame,
window,
cx,
)
})
.ok();
}
},
);
menu = menu.separator();
menu = menu.toggleable_entry(
"Vim Mode",
vim_mode_enabled,
IconPosition::Start,
None,
{
move |window, cx| {
let new_value = !vim_mode_enabled;
VimModeSetting::override_global(VimModeSetting(new_value), cx);
window.refresh();
}
},
);
menu
});
Some(menu)
})