Skip to content

Commit e41a2f2

Browse files
mangasFrederik Vestre
authored andcommitted
Add :reload-all command (helix-editor#4663)
1 parent e883e51 commit e41a2f2

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

book/src/generated/typable-cmd.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
| `:show-directory`, `:pwd` | Show the current working directory. |
4545
| `:encoding` | Set encoding. Based on `https://encoding.spec.whatwg.org`. |
4646
| `:reload` | Discard changes and reload from the source file. |
47+
| `:reload-all` | Discard changes and reload all documents from the source files. |
4748
| `:update` | Write changes only if the file has been modified. |
4849
| `:lsp-workspace-command` | Open workspace command picker |
4950
| `:lsp-restart` | Restarts the Language Server that is in use by the current doc |

helix-term/src/commands/typed.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,50 @@ fn reload(
10341034
})
10351035
}
10361036

1037+
fn reload_all(
1038+
cx: &mut compositor::Context,
1039+
_args: &[Cow<str>],
1040+
event: PromptEvent,
1041+
) -> anyhow::Result<()> {
1042+
if event != PromptEvent::Validate {
1043+
return Ok(());
1044+
}
1045+
1046+
let scrolloff = cx.editor.config().scrolloff;
1047+
let view_id = view!(cx.editor).id;
1048+
1049+
let docs_view_ids: Vec<(DocumentId, Vec<ViewId>)> = cx
1050+
.editor
1051+
.documents_mut()
1052+
.map(|doc| {
1053+
let mut view_ids: Vec<_> = doc.selections().keys().cloned().collect();
1054+
1055+
if view_ids.is_empty() {
1056+
doc.ensure_view_init(view_id);
1057+
view_ids.push(view_id);
1058+
};
1059+
1060+
(doc.id(), view_ids)
1061+
})
1062+
.collect();
1063+
1064+
for (doc_id, view_ids) in docs_view_ids {
1065+
let doc = doc_mut!(cx.editor, &doc_id);
1066+
1067+
// Every doc is guaranteed to have at least 1 view at this point.
1068+
let view = view_mut!(cx.editor, view_ids[0]);
1069+
doc.reload(view)?;
1070+
1071+
for view_id in view_ids {
1072+
let view = view_mut!(cx.editor, view_id);
1073+
1074+
view.ensure_cursor_in_view(doc, scrolloff);
1075+
}
1076+
}
1077+
1078+
Ok(())
1079+
}
1080+
10371081
/// Update the [`Document`] if it has been modified.
10381082
fn update(
10391083
cx: &mut compositor::Context,
@@ -2051,6 +2095,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
20512095
fun: reload,
20522096
completer: None,
20532097
},
2098+
TypableCommand {
2099+
name: "reload-all",
2100+
aliases: &[],
2101+
doc: "Discard changes and reload all documents from the source files.",
2102+
fun: reload_all,
2103+
completer: None,
2104+
},
20542105
TypableCommand {
20552106
name: "update",
20562107
aliases: &[],

0 commit comments

Comments
 (0)