Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the amount of horizontal splits you can do #4642

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
33 changes: 33 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ fn hsplit(
}

let id = view!(cx.editor).doc;
let view_id = view!(cx.editor).id;

if args.is_empty() {
cx.editor.switch(id, Action::HorizontalSplit);
Expand All @@ -1162,6 +1163,21 @@ fn hsplit(
}
}

// check if there are views with height equal to 1
// if there are, close the newly created view
if cx
.editor
.tree
.views()
.any(|(view, _focused)| view.area.height == 1)
{
cx.editor.set_error("Max number of splits reached");
cx.editor.close(view!(cx.editor).id);

// focus the view from which the split was called
cx.editor.focus(view_id);
}

Ok(())
}

Expand All @@ -1188,8 +1204,25 @@ fn hsplit_new(
return Ok(());
}

let view_id = view!(cx.editor).id;

cx.editor.new_file(Action::HorizontalSplit);

// check if there are views with height equal to 1
// if there are, close the newly created view
if cx
.editor
.tree
.views()
.any(|(view, _focused)| view.area.height == 1)
{
cx.editor.set_error("Max number of splits reached");
cx.editor.close(view!(cx.editor).id);

// focus the view from which the split was called
cx.editor.focus(view_id);
}

Ok(())
}

Expand Down