Add ability to reload a file (#18395)

Closes #13212

Release Notes:

- Added reload command
- vim: Added `:e[dit]`, `:e[dit]!` which calls reload
This commit is contained in:
Peter Schilling 2024-10-15 12:02:18 -07:00 committed by GitHub
parent 695176898e
commit 56163b1e35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 3 deletions

View file

@ -294,6 +294,7 @@ gpui::actions!(
RevealInFileManager,
ReverseLines,
RevertFile,
ReloadFile,
RevertSelectedHunks,
Rewrap,
ScrollCursorBottom,

View file

@ -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,
}

View file

@ -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) {

View file

@ -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),
]
}