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

View file

@ -48,7 +48,10 @@ pub use item::{
ProjectItem, SerializableItem, SerializableItemHandle, WeakItemHandle,
};
use itertools::Itertools;
use language::{Buffer, LanguageRegistry, Rope};
use language::{
Buffer, LanguageRegistry, Rope,
language_settings::{AllLanguageSettings, all_language_settings},
};
pub use modal_layer::*;
use node_runtime::NodeRuntime;
use notifications::{
@ -74,7 +77,7 @@ use remote::{SshClientDelegate, SshConnectionOptions, ssh_session::ConnectionIde
use schemars::JsonSchema;
use serde::Deserialize;
use session::AppSession;
use settings::Settings;
use settings::{Settings, update_settings_file};
use shared_screen::SharedScreen;
use sqlez::{
bindable::{Bind, Column, StaticColumnCount},
@ -233,6 +236,8 @@ actions!(
ToggleBottomDock,
/// Toggles centered layout mode.
ToggleCenteredLayout,
/// Toggles edit prediction feature globally for all files.
ToggleEditPrediction,
/// Toggles the left dock.
ToggleLeftDock,
/// Toggles the right dock.
@ -5546,6 +5551,7 @@ impl Workspace {
.on_action(cx.listener(Self::activate_pane_at_index))
.on_action(cx.listener(Self::move_item_to_pane_at_index))
.on_action(cx.listener(Self::move_focused_panel_to_next_position))
.on_action(cx.listener(Self::toggle_edit_predictions_all_files))
.on_action(cx.listener(|workspace, _: &Unfollow, window, cx| {
let pane = workspace.active_pane().clone();
workspace.unfollow_in_pane(&pane, window, cx);
@ -5977,6 +5983,19 @@ impl Workspace {
}
});
}
fn toggle_edit_predictions_all_files(
&mut self,
_: &ToggleEditPrediction,
_window: &mut Window,
cx: &mut Context<Self>,
) {
let fs = self.project().read(cx).fs().clone();
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 leader_border_for_pane(