mirror of https://github.com/helix-editor/helix
fix(commands): run fmt for all documents being closed (#1444)
When writing all documents, fmt wouldn't be run. Run fmt in close all implementation so that all documents are formatted if necessary. Fixes: https://github.com/helix-editor/helix/issues/1442pull/1470/head
parent
62c78c061c
commit
38ca8daa09
|
@ -2279,7 +2279,7 @@ pub mod cmd {
|
||||||
force: bool,
|
force: bool,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut errors = String::new();
|
let mut errors = String::new();
|
||||||
|
let jobs = &mut cx.jobs;
|
||||||
// save all documents
|
// save all documents
|
||||||
for doc in &mut cx.editor.documents.values_mut() {
|
for doc in &mut cx.editor.documents.values_mut() {
|
||||||
if doc.path().is_none() {
|
if doc.path().is_none() {
|
||||||
|
@ -2287,9 +2287,23 @@ pub mod cmd {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle error.
|
if !doc.is_modified() {
|
||||||
let handle = doc.save();
|
continue;
|
||||||
cx.jobs.add(Job::new(handle).wait_before_exiting());
|
}
|
||||||
|
|
||||||
|
let fmt = doc.auto_format().map(|fmt| {
|
||||||
|
let shared = fmt.shared();
|
||||||
|
let callback = make_format_callback(
|
||||||
|
doc.id(),
|
||||||
|
doc.version(),
|
||||||
|
Modified::SetUnmodified,
|
||||||
|
shared.clone(),
|
||||||
|
);
|
||||||
|
jobs.callback(callback);
|
||||||
|
shared
|
||||||
|
});
|
||||||
|
let future = doc.format_and_save(fmt);
|
||||||
|
jobs.add(Job::new(future).wait_before_exiting());
|
||||||
}
|
}
|
||||||
|
|
||||||
if quit {
|
if quit {
|
||||||
|
|
Loading…
Reference in New Issue