Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add ability to reload a file (#18395)
Peter Schilling56163b1e3595
diff --git a/crates/editor/src/actions.rs b/crates/editor/src/actions.rsindex 502b70361b4..b0c7877979f 100644--- a/crates/editor/src/actions.rs+++ b/crates/editor/src/actions.rs@@ -294,6 +294,7 @@ gpui::actions!(RevealInFileManager,ReverseLines,RevertFile,+ ReloadFile,RevertSelectedHunks,Rewrap,ScrollCursorBottom,diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 453c012e4d7..d07002040c5 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -161,11 +161,11 @@ use ui::{};use util::{defer, maybe, post_inc, RangeExt, ResultExt, TryFutureExt};use workspace::item::{ItemHandle, PreviewTabsSettings};-use workspace::notifications::{DetachAndPromptErr, NotificationId};+use workspace::notifications::{DetachAndPromptErr, NotificationId, NotifyTaskExt};use workspace::{searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace, WorkspaceId,};-use workspace::{OpenInTerminal, OpenTerminal, TabBarSettings, Toast};+use workspace::{Item as WorkspaceItem, OpenInTerminal, OpenTerminal, TabBarSettings, Toast};use crate::hover_links::find_url;use crate::signature_help::{SignatureHelpHiddenBy, SignatureHelpState};@@ -6241,6 +6241,13 @@ impl Editor {}}+ pub fn reload_file(&mut self, _: &ReloadFile, cx: &mut ViewContext<Self>) {+ let Some(project) = self.project.clone() else {+ return;+ };+ self.reload(project, cx).detach_and_notify_err(cx);+ }+pub fn revert_selected_hunks(&mut self, _: &RevertSelectedHunks, cx: &mut ViewContext<Self>) {let revert_changes = self.gather_revert_changes(&self.selections.disjoint_anchors(), cx);if !revert_changes.is_empty() {@@ -13624,6 +13631,7 @@ pub enum EditorEvent {TransactionBegun {transaction_id: clock::Lamport,},+ Reloaded,CursorShapeChanged,}diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 8a2ec5cd0d5..49bb9d7b925 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -437,7 +437,8 @@ impl EditorElement {register_action(view, cx, Editor::revert_file);register_action(view, cx, Editor::revert_selected_hunks);register_action(view, cx, Editor::apply_selected_diff_hunks);- register_action(view, cx, Editor::open_active_item_in_terminal)+ register_action(view, cx, Editor::open_active_item_in_terminal);+ register_action(view, cx, Editor::reload_file)}fn register_key_listeners(&self, cx: &mut WindowContext, layout: &EditorLayout) {diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rsindex 605bc3a05e4..47975f4cfd0 100644--- a/crates/vim/src/command.rs+++ b/crates/vim/src/command.rs@@ -685,6 +685,8 @@ fn generate_commands(_: &AppContext) -> Vec<VimCommand> {VimCommand::new(("$", ""), EndOfDocument),VimCommand::new(("%", ""), EndOfDocument),VimCommand::new(("0", ""), StartOfDocument),+ VimCommand::new(("e", "dit"), editor::actions::ReloadFile)+ .bang(editor::actions::ReloadFile),]}