on master help sign in
fix: Don't allow closing the last split if there's unsaved changes

Fixes #674

commit3ff5b001ac721606b68a594958abeee8832a023e authorBlaž Hrastnik <blaz@mxxn.io> dateFri 17 Sep 2021, 14:42 (5 years ago) parentc7d6e44
1 file changed+7−1
helix-term/src/commands.rs+7−1
helix-term/src/commands.rs+7−1
@@ -1568,7 +1568,7 @@ mod cmd {
15681568
15691569 /// Results an error if there are modified buffers remaining and sets editor error,
15701570 /// otherwise returns `Ok(())`
1571− fn buffers_remaining_impl(editor: &mut Editor) -> anyhow::Result<()> {
1571+ pub(super) fn buffers_remaining_impl(editor: &mut Editor) -> anyhow::Result<()> {
15721572 let modified: Vec<_> = editor
15731573 .documents()
15741574 .filter(|doc| doc.is_modified())
@@ -4157,6 +4157,12 @@ fn vsplit(cx: &mut Context) {
41574157}
41584158
41594159fn wclose(cx: &mut Context) {
4160+ if cx.editor.tree.views().count() == 1 {
4161+ if let Err(err) = cmd::buffers_remaining_impl(cx.editor) {
4162+ cx.editor.set_error(err.to_string());
4163+ return;
4164+ }
4165+ }
41604166 let view_id = view!(cx.editor).id;
41614167 // close current split
41624168 cx.editor.close(view_id, /* close_buffer */ false);