Accept finished inline transformations only if the user saves manually (#16112)
Closes https://github.com/zed-industries/zed/issues/16042 This commit modifies the behavior of inline transformations to only accept finished transformations when the user manually saves the file. Previously, transformations were automatically accepted on any save event, including autosaves. This was achieved by updating the `Pane` and `Workspace` structs to emit a new `UserSavedItem` event when a manual save occurs, and modifying the `InlineAssistant` to register and handle this new event (instead of `editor::Saved`). Release Notes: - N/A
This commit is contained in:
parent
48f6193628
commit
a15a9565ab
4 changed files with 74 additions and 14 deletions
|
@ -436,6 +436,7 @@ pub trait ItemHandle: 'static + Send {
|
|||
|
||||
pub trait WeakItemHandle: Send + Sync {
|
||||
fn id(&self) -> EntityId;
|
||||
fn boxed_clone(&self) -> Box<dyn WeakItemHandle>;
|
||||
fn upgrade(&self) -> Option<Box<dyn ItemHandle>>;
|
||||
}
|
||||
|
||||
|
@ -852,6 +853,10 @@ impl<T: Item> WeakItemHandle for WeakView<T> {
|
|||
self.entity_id()
|
||||
}
|
||||
|
||||
fn boxed_clone(&self) -> Box<dyn WeakItemHandle> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
fn upgrade(&self) -> Option<Box<dyn ItemHandle>> {
|
||||
self.upgrade().map(|v| Box::new(v) as Box<dyn ItemHandle>)
|
||||
}
|
||||
|
|
|
@ -166,16 +166,28 @@ impl DeploySearch {
|
|||
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;
|
||||
|
||||
pub enum Event {
|
||||
AddItem { item: Box<dyn ItemHandle> },
|
||||
ActivateItem { local: bool },
|
||||
AddItem {
|
||||
item: Box<dyn ItemHandle>,
|
||||
},
|
||||
ActivateItem {
|
||||
local: bool,
|
||||
},
|
||||
Remove,
|
||||
RemoveItem { idx: usize },
|
||||
RemovedItem { item_id: EntityId },
|
||||
RemoveItem {
|
||||
idx: usize,
|
||||
},
|
||||
RemovedItem {
|
||||
item_id: EntityId,
|
||||
},
|
||||
Split(SplitDirection),
|
||||
ChangeItemTitle,
|
||||
Focus,
|
||||
ZoomIn,
|
||||
ZoomOut,
|
||||
UserSavedItem {
|
||||
item: Box<dyn WeakItemHandle>,
|
||||
save_intent: SaveIntent,
|
||||
},
|
||||
}
|
||||
|
||||
impl fmt::Debug for Event {
|
||||
|
@ -203,6 +215,11 @@ impl fmt::Debug for Event {
|
|||
Event::Focus => f.write_str("Focus"),
|
||||
Event::ZoomIn => f.write_str("ZoomIn"),
|
||||
Event::ZoomOut => f.write_str("ZoomOut"),
|
||||
Event::UserSavedItem { item, save_intent } => f
|
||||
.debug_struct("UserSavedItem")
|
||||
.field("item", &item.id())
|
||||
.field("save_intent", save_intent)
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1494,7 +1511,13 @@ impl Pane {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(true)
|
||||
pane.update(cx, |_, cx| {
|
||||
cx.emit(Event::UserSavedItem {
|
||||
item: item.downgrade_item(),
|
||||
save_intent,
|
||||
});
|
||||
true
|
||||
})
|
||||
}
|
||||
|
||||
fn can_autosave_item(item: &dyn ItemHandle, cx: &AppContext) -> bool {
|
||||
|
|
|
@ -40,7 +40,7 @@ use gpui::{
|
|||
};
|
||||
use item::{
|
||||
FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, PreviewTabsSettings,
|
||||
ProjectItem, SerializableItem, SerializableItemHandle,
|
||||
ProjectItem, SerializableItem, SerializableItemHandle, WeakItemHandle,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use language::{LanguageRegistry, Rope};
|
||||
|
@ -670,6 +670,11 @@ pub enum Event {
|
|||
ItemAdded,
|
||||
ItemRemoved,
|
||||
ActiveItemChanged,
|
||||
UserSavedItem {
|
||||
pane: WeakView<Pane>,
|
||||
item: Box<dyn WeakItemHandle>,
|
||||
save_intent: SaveIntent,
|
||||
},
|
||||
ContactRequestedJoin(u64),
|
||||
WorkspaceCreated(WeakView<Workspace>),
|
||||
SpawnTask(Box<SpawnInTerminal>),
|
||||
|
@ -2934,6 +2939,11 @@ impl Workspace {
|
|||
self.update_active_view_for_followers(cx);
|
||||
}
|
||||
}
|
||||
pane::Event::UserSavedItem { item, save_intent } => cx.emit(Event::UserSavedItem {
|
||||
pane: pane.downgrade(),
|
||||
item: item.boxed_clone(),
|
||||
save_intent: *save_intent,
|
||||
}),
|
||||
pane::Event::ChangeItemTitle => {
|
||||
if pane == self.active_pane {
|
||||
self.active_item_path_changed(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue