-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 vertical splits you can do #4726
Open
janhrastnik
wants to merge
6
commits into
helix-editor:master
Choose a base branch
from
janhrastnik:vsplit_limit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−18
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
43581d6
changed recalculate() in tree.rs, added a vsplit limit check function…
janhrastnik 3c56f39
can_do_vsplit now checks if the one character wide view is a child of…
janhrastnik c771041
added clippy lint
janhrastnik ce0960a
Merge branch 'helix-editor:master' into vsplit_limit
janhrastnik 45820cb
inner_area() now takes Document as an argument
janhrastnik 9bef3f2
applied changes from code review
janhrastnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,6 +214,20 @@ impl Tree { | |
node | ||
} | ||
|
||
pub fn is_child(&self, child_id: &ViewId) -> bool { | ||
let focus = self.focus; | ||
let parent = self.nodes[focus].parent; | ||
|
||
let container_children: Vec<ViewId> = match &self.nodes[parent] { | ||
Node { | ||
content: Content::Container(container), | ||
.. | ||
} => container.children.clone(), | ||
_ => unimplemented!(), | ||
}; | ||
container_children.contains(child_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can avoid the cloning by doing the match &self.nodes[parent] {
Node {
content: Content::Container(container),
..
} => container.children.contains(child_id),
_ => unreachable!(),
} |
||
} | ||
|
||
pub fn remove(&mut self, index: ViewId) { | ||
let mut stack = Vec::new(); | ||
|
||
|
@@ -385,22 +399,21 @@ impl Tree { | |
} | ||
Layout::Vertical => { | ||
let len = container.children.len(); | ||
let inner_gap = 1u16; | ||
|
||
let width = area.width / len as u16; | ||
|
||
let inner_gap = 1u16; | ||
// let total_gap = inner_gap * (len as u16 - 1); | ||
|
||
let mut child_x = area.x; | ||
|
||
for (i, child) in container.children.iter().enumerate() { | ||
let mut area = Rect::new( | ||
child_x, | ||
container.area.y, | ||
width, | ||
// we subtract inner gap here to accommodate for the width that inner gaps take | ||
width - inner_gap, | ||
container.area.height, | ||
); | ||
child_x += width + inner_gap; | ||
child_x += width; | ||
|
||
// last child takes the remaining width because we can get uneven | ||
// space from rounding | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be unreachable since we're looking at a parent node in the tree