Skip to content

Commit

Permalink
fix: Don't allow closing the last split if there's unsaved changes
Browse files Browse the repository at this point in the history
Fixes #674
  • Loading branch information
archseer committed Sep 17, 2021
1 parent c7d6e44 commit 3ff5b00
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ mod cmd {

/// Results an error if there are modified buffers remaining and sets editor error,
/// otherwise returns `Ok(())`
fn buffers_remaining_impl(editor: &mut Editor) -> anyhow::Result<()> {
pub(super) fn buffers_remaining_impl(editor: &mut Editor) -> anyhow::Result<()> {
let modified: Vec<_> = editor
.documents()
.filter(|doc| doc.is_modified())
Expand Down Expand Up @@ -4157,6 +4157,12 @@ fn vsplit(cx: &mut Context) {
}

fn wclose(cx: &mut Context) {
if cx.editor.tree.views().count() == 1 {
if let Err(err) = cmd::buffers_remaining_impl(cx.editor) {
cx.editor.set_error(err.to_string());
return;
}
}
let view_id = view!(cx.editor).id;
// close current split
cx.editor.close(view_id, /* close_buffer */ false);
Expand Down

0 comments on commit 3ff5b00

Please sign in to comment.