Add workspace::ToggleEditPrediction for toggling inline completions globally (#35418)

Closes: https://github.com/zed-industries/zed/issues/23704

Existing action is `editor::ToggleEditPrediction` ("This Buffer").
This action is `workspace::ToggleEditPredction` ("All Files").

You can add a custom keybind wi shortcut with:
```json
  { "context": "Workspace", "bindings": { "ctrl-alt-cmd-e": "workspace::ToggleEditPrediction" } },
```

<img width="212" height="439" alt="Screenshot 2025-07-31 at 12 52 19"
src="https://github.com/user-attachments/assets/15879daa-7d4d-4308-ab2b-5e78507f2fa5"
/>


Release Notes:

- Added `workspace::ToggleEditPrediction` action for toggling
`show_edit_predictions` in settings (Edit Predictions menu -> All
Files).
This commit is contained in:
Peter Tripp 2025-08-05 09:35:52 -04:00 committed by GitHub
parent 497252480c
commit 5b40b3618f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 20 deletions

View file

@ -2,11 +2,7 @@ use anyhow::Result;
use client::{UserStore, zed_urls};
use cloud_llm_client::UsageLimit;
use copilot::{Copilot, Status};
use editor::{
Editor, SelectionEffects,
actions::{ShowEditPrediction, ToggleEditPrediction},
scroll::Autoscroll,
};
use editor::{Editor, SelectionEffects, actions::ShowEditPrediction, scroll::Autoscroll};
use feature_flags::{FeatureFlagAppExt, PredictEditsRateCompletionsFeatureFlag};
use fs::Fs;
use gpui::{
@ -441,9 +437,13 @@ impl EditPredictionButton {
if let Some(editor_focus_handle) = self.editor_focus_handle.clone() {
let entry = ContextMenuEntry::new("This Buffer")
.toggleable(IconPosition::Start, self.editor_show_predictions)
.action(Box::new(ToggleEditPrediction))
.action(Box::new(editor::actions::ToggleEditPrediction))
.handler(move |window, cx| {
editor_focus_handle.dispatch_action(&ToggleEditPrediction, window, cx);
editor_focus_handle.dispatch_action(
&editor::actions::ToggleEditPrediction,
window,
cx,
);
});
match language_state.clone() {
@ -478,10 +478,13 @@ impl EditPredictionButton {
let settings = AllLanguageSettings::get_global(cx);
let globally_enabled = settings.show_edit_predictions(None, cx);
menu = menu.toggleable_entry("All Files", globally_enabled, IconPosition::Start, None, {
let fs = fs.clone();
move |_, cx| toggle_edit_predictions_globally(fs.clone(), cx)
});
let entry = ContextMenuEntry::new("All Files")
.toggleable(IconPosition::Start, globally_enabled)
.action(workspace::ToggleEditPrediction.boxed_clone())
.handler(|window, cx| {
window.dispatch_action(workspace::ToggleEditPrediction.boxed_clone(), cx)
});
menu = menu.item(entry);
let provider = settings.edit_predictions.provider;
let current_mode = settings.edit_predictions_mode();
@ -943,13 +946,6 @@ async fn open_disabled_globs_setting_in_editor(
anyhow::Ok(())
}
fn toggle_edit_predictions_globally(fs: Arc<dyn Fs>, cx: &mut App) {
let show_edit_predictions = all_language_settings(None, cx).show_edit_predictions(None, cx);
update_settings_file::<AllLanguageSettings>(fs, cx, move |file, _| {
file.defaults.show_edit_predictions = Some(!show_edit_predictions)
});
}
fn set_completion_provider(fs: Arc<dyn Fs>, cx: &mut App, provider: EditPredictionProvider) {
update_settings_file::<AllLanguageSettings>(fs, cx, move |file, _| {
file.features