on master help sign in
fix: Don't allow closing the last split if there's unsaved changes
3ff5b00Blaž Hrastnik
helix-term/src/commands.rs+7−1
@@ -1568,7 +1568,7 @@ mod cmd {
1568
1568
1569 /// Results an error if there are modified buffers remaining and sets editor error,
1569 /// Results an error if there are modified buffers remaining and sets editor error,
1570 /// otherwise returns `Ok(())`
1570 /// 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<()> {
1572 let modified: Vec<_> = editor
1572 let modified: Vec<_> = editor
1573 .documents()
1573 .documents()
1574 .filter(|doc| doc.is_modified())
1574 .filter(|doc| doc.is_modified())
@@ -4157,6 +4157,12 @@ fn vsplit(cx: &mut Context) {
4157}
4157}
4158
4158
4159fn wclose(cx: &mut Context) {
4159fn 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+ }
4160 let view_id = view!(cx.editor).id;
4166 let view_id = view!(cx.editor).id;
4161 // close current split
4167 // close current split
4162 cx.editor.close(view_id, /* close_buffer */ false);
4168 cx.editor.close(view_id, /* close_buffer */ false);