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

feat: directional move focus #55 #78

Merged
merged 10 commits into from
Dec 4, 2020
Merged

Conversation

denismaxim0v
Copy link
Member

No description provided.

@denismaxim0v
Copy link
Member Author

that's still wip, I'll write the tests later on today

@h3nill
Copy link
Member

h3nill commented Nov 30, 2020

I have tried the branch locally and it's working great for me. Just leaving some nitpicks which came to my mind from the first look.

src/screen.rs Outdated
Comment on lines 1372 to 1398
match active_terminal {
Some(active) => {
let next_index = self
.terminals
.iter()
.enumerate()
.filter(|(_, (_, c))| {
c.is_directly_above(&active) && c.vertically_overlaps_with(&active)
})
.max_by_key(|(_, (_, c))| c.get_vertical_overlap_with(&active))
.map(|(_, (pid, _))| pid);
match next_index {
Some(p) => {
self.active_terminal = Some(*p);
()
}
None => {
self.active_terminal = Some(active.pid);
()
}
}
}
None => {
self.active_terminal = Some(active_terminal.unwrap().pid);
()
}
}
Copy link
Member

@h3nill h3nill Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this match statements should be reduced to if let, as it improves readability and that's what if let statements are for. And also reduces a level of indent :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this can be reduced

src/screen.rs Outdated
Comment on lines 1409 to 1435
match active_terminal {
Some(active) => {
let next_index = self
.terminals
.iter()
.enumerate()
.filter(|(_, (_, c))| {
c.is_directly_right_of(&active) && c.horizontally_overlaps_with(&active)
})
.max_by_key(|(_, (_, c))| c.get_horizontal_overlap_with(&active))
.map(|(_, (pid, _))| pid);
match next_index {
Some(p) => {
self.active_terminal = Some(*p);
()
}
None => {
self.active_terminal = Some(active.pid);
()
}
}
}
None => {
self.active_terminal = Some(active_terminal.unwrap().pid);
()
}
}
Copy link
Member

@h3nill h3nill Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

src/screen.rs Outdated
Comment on lines 1335 to 1361
match active_terminal {
Some(active) => {
let next_index = self
.terminals
.iter()
.enumerate()
.filter(|(_, (_, c))| {
c.is_directly_below(&active) && c.vertically_overlaps_with(&active)
})
.max_by_key(|(_, (_, c))| c.get_vertical_overlap_with(&active))
.map(|(_, (pid, _))| pid);
match next_index {
Some(p) => {
self.active_terminal = Some(*p);
()
}
None => {
self.active_terminal = Some(active.pid);
()
}
}
}
None => {
self.active_terminal = Some(active_terminal.unwrap().pid);
()
}
}
Copy link
Member

@h3nill h3nill Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

src/screen.rs Outdated
Comment on lines 1298 to 1324
match active_terminal {
Some(active) => {
let next_index = self
.terminals
.iter()
.enumerate()
.filter(|(_, (_, c))| {
c.is_directly_left_of(&active) && c.horizontally_overlaps_with(&active)
})
.max_by_key(|(_, (_, c))| c.get_horizontal_overlap_with(&active))
.map(|(_, (pid, _))| pid);
match next_index {
Some(p) => {
self.active_terminal = Some(*p);
()
}
None => {
self.active_terminal = Some(active.pid);
()
}
}
}
None => {
self.active_terminal = Some(active_terminal.unwrap().pid);
()
}
}
Copy link
Member

@h3nill h3nill Nov 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@imsnif
Copy link
Member

imsnif commented Nov 30, 2020

Hey @denismaxim0v - on the surface this looks great. Before I go deeper into it, do you think you can add some tests for these? There are quite some edge cases here that we should probably be testing. (eg. making sure it picks the terminal with the largest overlap in each case, etc.) You can look at some of the resize tests in this repo for inspiration.

@denismaxim0v
Copy link
Member Author

Hey @denismaxim0v - on the surface this looks great. Before I go deeper into it, do you think you can add some tests for these? There are quite some edge cases here that we should probably be testing. (eg. making sure it picks the terminal with the largest overlap in each case, etc.) You can look at some of the resize tests in this repo for inspiration.

Yup, working on it, gonna commit those tomorrow

Comment on lines +1308 to +1315
match next_index {
Some(p) => {
self.active_terminal = Some(*p);
}
None => {
self.active_terminal = Some(active.pid);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the previous ones, perhaps these inner ones can too be reduced.

Comment on lines +1339 to +1346
match next_index {
Some(p) => {
self.active_terminal = Some(*p);
}
None => {
self.active_terminal = Some(active.pid);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Comment on lines +1370 to +1377
match next_index {
Some(p) => {
self.active_terminal = Some(*p);
}
None => {
self.active_terminal = Some(active.pid);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Comment on lines +1401 to +1408
match next_index {
Some(p) => {
self.active_terminal = Some(*p);
}
None => {
self.active_terminal = Some(active.pid);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Member

@imsnif imsnif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! I'm looking forward to this feature :)

Great work. The code looks very clean and the tests are great. I left two relatively minor comments and after addressing them I think we can merge this.

self.get_x() + self.get_columns(),
other.get_x() + other.get_columns(),
) - std::cmp::max(self.get_x(), other.get_x())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we can implement these on the Rect trait instead of on terminal_pane? That way when we add other pane types (eg. plugins) they will get this for free.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, don't see why it can't be moved, will do

&SPLIT_VERTICALLY,
&MOVE_FOCUS_UP,
&MOVE_FOCUS_DOWN,
&QUIT,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but I think here both pane candidates are of the same size, aren't they? Maybe we can adjust the size of one of them using a resize command in this input? (this is true to the other tests as well, I think)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, my bad, will push it with a resize

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I look at it I do the vertical split two times so the panes are 25%, 25%, 50% so it's still testing whether it switches to the most overlapping one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. My bad :)

Copy link
Member

@imsnif imsnif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution with Self - I did not know you could do that :)

@imsnif imsnif merged commit b7b3ff7 into zellij-org:main Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants