Skip to content

Commit 4259f63

Browse files
committed
Don't complain if scratch is modified on autosave
1 parent 4240cf4 commit 4259f63

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

helix-term/src/commands/typed.rs

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -535,28 +535,24 @@ pub(super) fn buffers_remaining_impl(editor: &mut Editor) -> anyhow::Result<()>
535535
Ok(())
536536
}
537537

538-
fn write_all_impl(
538+
pub fn write_all_impl(
539539
cx: &mut compositor::Context,
540-
_args: &[Cow<str>],
541-
event: PromptEvent,
542-
quit: bool,
543540
force: bool,
541+
write_scratch: bool,
544542
) -> anyhow::Result<()> {
545-
if event != PromptEvent::Validate {
546-
return Ok(());
547-
}
548-
549543
let mut errors = String::new();
550544
let auto_format = cx.editor.config().auto_format;
551545
let jobs = &mut cx.jobs;
552546
// save all documents
553547
for doc in &mut cx.editor.documents.values_mut() {
554-
if doc.path().is_none() {
555-
errors.push_str("cannot write a buffer without a filename\n");
548+
if !doc.is_modified() {
556549
continue;
557550
}
558551

559-
if !doc.is_modified() {
552+
if doc.path().is_none() {
553+
if write_scratch {
554+
errors.push_str("cannot write a buffer without a filename\n");
555+
}
560556
continue;
561557
}
562558

@@ -579,55 +575,46 @@ fn write_all_impl(
579575
jobs.add(Job::new(future).wait_before_exiting());
580576
}
581577

582-
if quit {
583-
if !force {
584-
buffers_remaining_impl(cx.editor)?;
585-
}
586-
587-
// close all views
588-
let views: Vec<_> = cx.editor.tree.views().map(|(view, _)| view.id).collect();
589-
for view_id in views {
590-
cx.editor.close(view_id);
591-
}
578+
match errors.len() {
579+
0 => Ok(()),
580+
_ => bail!(errors),
592581
}
593-
594-
bail!(errors)
595582
}
596583

597-
pub fn write_all(
584+
fn write_all(
598585
cx: &mut compositor::Context,
599-
args: &[Cow<str>],
586+
_args: &[Cow<str>],
600587
event: PromptEvent,
601588
) -> anyhow::Result<()> {
602589
if event != PromptEvent::Validate {
603590
return Ok(());
604591
}
605592

606-
write_all_impl(cx, args, event, false, false)
593+
write_all_impl(cx, false, true)
607594
}
608595

609596
fn write_all_quit(
610597
cx: &mut compositor::Context,
611-
args: &[Cow<str>],
598+
_args: &[Cow<str>],
612599
event: PromptEvent,
613600
) -> anyhow::Result<()> {
614601
if event != PromptEvent::Validate {
615602
return Ok(());
616603
}
617-
618-
write_all_impl(cx, args, event, true, false)
604+
write_all_impl(cx, false, true)?;
605+
quit_all_impl(cx.editor, false)
619606
}
620607

621608
fn force_write_all_quit(
622609
cx: &mut compositor::Context,
623-
args: &[Cow<str>],
610+
_args: &[Cow<str>],
624611
event: PromptEvent,
625612
) -> anyhow::Result<()> {
626613
if event != PromptEvent::Validate {
627614
return Ok(());
628615
}
629-
630-
write_all_impl(cx, args, event, true, true)
616+
let _ = write_all_impl(cx, true, true);
617+
quit_all_impl(cx.editor, true)
631618
}
632619

633620
fn quit_all_impl(editor: &mut Editor, force: bool) -> anyhow::Result<()> {

helix-term/src/ui/editor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
compositor::{Component, Context, Event, EventResult},
44
job, key,
55
keymap::{KeymapResult, Keymaps},
6-
ui::prompt::PromptEvent,
76
ui::{Completion, ProgressSpinners},
87
};
98

@@ -1253,8 +1252,7 @@ impl Component for EditorView {
12531252
Event::FocusGained => EventResult::Ignored(None),
12541253
Event::FocusLost => {
12551254
if context.editor.config().auto_save {
1256-
if let Err(e) = commands::typed::write_all(context, &[], PromptEvent::Validate)
1257-
{
1255+
if let Err(e) = commands::typed::write_all_impl(context, false, false) {
12581256
context.editor.set_error(format!("{}", e));
12591257
}
12601258
}

0 commit comments

Comments
 (0)