Skip to content

Commit 56163b1

Browse files
authored
Add ability to reload a file (#18395)
Closes #13212 Release Notes: - Added reload command - vim: Added `:e[dit]`, `:e[dit]!` which calls reload
1 parent 6951768 commit 56163b1

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

crates/editor/src/actions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ gpui::actions!(
294294
RevealInFileManager,
295295
ReverseLines,
296296
RevertFile,
297+
ReloadFile,
297298
RevertSelectedHunks,
298299
Rewrap,
299300
ScrollCursorBottom,

crates/editor/src/editor.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ use ui::{
161161
};
162162
use util::{defer, maybe, post_inc, RangeExt, ResultExt, TryFutureExt};
163163
use workspace::item::{ItemHandle, PreviewTabsSettings};
164-
use workspace::notifications::{DetachAndPromptErr, NotificationId};
164+
use workspace::notifications::{DetachAndPromptErr, NotificationId, NotifyTaskExt};
165165
use workspace::{
166166
searchable::SearchEvent, ItemNavHistory, SplitDirection, ViewId, Workspace, WorkspaceId,
167167
};
168-
use workspace::{OpenInTerminal, OpenTerminal, TabBarSettings, Toast};
168+
use workspace::{Item as WorkspaceItem, OpenInTerminal, OpenTerminal, TabBarSettings, Toast};
169169

170170
use crate::hover_links::find_url;
171171
use crate::signature_help::{SignatureHelpHiddenBy, SignatureHelpState};
@@ -6241,6 +6241,13 @@ impl Editor {
62416241
}
62426242
}
62436243

6244+
pub fn reload_file(&mut self, _: &ReloadFile, cx: &mut ViewContext<Self>) {
6245+
let Some(project) = self.project.clone() else {
6246+
return;
6247+
};
6248+
self.reload(project, cx).detach_and_notify_err(cx);
6249+
}
6250+
62446251
pub fn revert_selected_hunks(&mut self, _: &RevertSelectedHunks, cx: &mut ViewContext<Self>) {
62456252
let revert_changes = self.gather_revert_changes(&self.selections.disjoint_anchors(), cx);
62466253
if !revert_changes.is_empty() {
@@ -13624,6 +13631,7 @@ pub enum EditorEvent {
1362413631
TransactionBegun {
1362513632
transaction_id: clock::Lamport,
1362613633
},
13634+
Reloaded,
1362713635
CursorShapeChanged,
1362813636
}
1362913637

crates/editor/src/element.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ impl EditorElement {
437437
register_action(view, cx, Editor::revert_file);
438438
register_action(view, cx, Editor::revert_selected_hunks);
439439
register_action(view, cx, Editor::apply_selected_diff_hunks);
440-
register_action(view, cx, Editor::open_active_item_in_terminal)
440+
register_action(view, cx, Editor::open_active_item_in_terminal);
441+
register_action(view, cx, Editor::reload_file)
441442
}
442443

443444
fn register_key_listeners(&self, cx: &mut WindowContext, layout: &EditorLayout) {

crates/vim/src/command.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ fn generate_commands(_: &AppContext) -> Vec<VimCommand> {
685685
VimCommand::new(("$", ""), EndOfDocument),
686686
VimCommand::new(("%", ""), EndOfDocument),
687687
VimCommand::new(("0", ""), StartOfDocument),
688+
VimCommand::new(("e", "dit"), editor::actions::ReloadFile)
689+
.bang(editor::actions::ReloadFile),
688690
]
689691
}
690692

0 commit comments

Comments
 (0)