Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

zeta2: Support `edit prediction: clear history` (#38808)

Bennet Bo Fenner6b646e3a14ae
diff --git a/crates/zed/src/zed/edit_prediction_registry.rs b/crates/zed/src/zed/edit_prediction_registry.rs
index d0e8e260742..5d099834b92 100644
--- a/crates/zed/src/zed/edit_prediction_registry.rs
+++ b/crates/zed/src/zed/edit_prediction_registry.rs
@@ -97,6 +97,8 @@ pub fn init(client: Arc<Client>, user_store: Entity<UserStore>, cx: &mut App) {
fn clear_zeta_edit_history(_: &zeta::ClearHistory, cx: &mut App) {
if let Some(zeta) = zeta::Zeta::global(cx) {
zeta.update(cx, |zeta, _| zeta.clear_history());
+ } else if let Some(zeta) = zeta2::Zeta::try_global(cx) {
+ zeta.update(cx, |zeta, _| zeta.clear_history());
}
}
diff --git a/crates/zeta2/src/zeta2.rs b/crates/zeta2/src/zeta2.rs
index 8af20a6236e..fcf42958a07 100644
--- a/crates/zeta2/src/zeta2.rs
+++ b/crates/zeta2/src/zeta2.rs
@@ -108,6 +108,10 @@ pub enum Event {
}
impl Zeta {
+ pub fn try_global(cx: &App) -> Option<Entity<Self>> {
+ cx.try_global::<ZetaGlobal>().map(|global| global.0.clone())
+ }
+
pub fn global(
client: &Arc<Client>,
user_store: &Entity<UserStore>,
@@ -162,6 +166,12 @@ impl Zeta {
self.options = options;
}
+ pub fn clear_history(&mut self) {
+ for zeta_project in self.projects.values_mut() {
+ zeta_project.events.clear();
+ }
+ }
+
pub fn usage(&self, cx: &App) -> Option<EditPredictionUsage> {
self.user_store.read(cx).edit_prediction_usage()
}