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

Clean up Pane #2494

Merged
merged 4 commits into from
Aug 28, 2019
Merged

Clean up Pane #2494

merged 4 commits into from
Aug 28, 2019

Conversation

richardszalay
Copy link
Contributor

@richardszalay richardszalay commented Aug 21, 2019

Cleanup of Pane.cpp based on conversations in #2450

Summary of the Pull Request

  • Merging of all Split{Horizontal,Vertical} methods into a single method that accepts Pane::SplitState
  • Rename Tab::(Can)AddSplit to (Can)SplitPane to keep the verb/noun usage consistent with Pane.cpp
  • Cleanup of a few other Pane methods, mostly removing unnecessarily nested else statements where the if always returns

When reviewing, it might be easier to split into renames and tidy up

Each change has been committed separately to make them easier to rebase out if you're not happy with them, but feel free to squash them when merging.

References

#2450

PR Checklist

  • Closes #xxx (not directly related to an issue)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed (N/A - there are no tests for Pane.cpp)
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: Prevent splitting panes into 0 width/height #2401 #2450

Detailed Description of the Pull Request / Additional comments

All covered by the "Summary" above.

Validation Steps Performed

Simple usage of the terminal, and hammering the split feature to ensure it still works (including the previously fixed crash fixed by #2450)

Having separate Horizontal/Vertical versions made it hard to manage, and App.cpp already made use of Pane::SplitState so it made sense to have that be the descriminator
Split was used as a noun in Tab but a verb in Pane, which felt odd
Improves readibility. All 'low hanging fruit' cases where the 'if' was returning.
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

I like it, but this is @zadjii-msft's world so I'd like to see his review before the final merge.

// our separator _is_ the correct direction, then we should be the pane
// to resize. Otherwise, just return false, as we couldn't handle it
// either.
if ((!_firstChild->_IsLeaf()) && _firstChild->_HasFocusedChild())
Copy link
Contributor

Choose a reason for hiding this comment

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

This pattern ("find the non-leaf's child, if it has one") appears a lot. Is there a way to pull it out into a helper? I know that we do slightly different things with each one, but the pattern looks the same:

if(!<x>.leaf && <x>.child) {
    make <x> do <A>, or do <_A> ourselves
}

perhaps we can:

auto x = _findFirstChildPaneMatchingThoseCriteriaOrNot();
return x.has_value() && x->A() || _A();

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Overall I'm happy with this - much cleaner than before. Thanks!

@DHowett-MSFT DHowett-MSFT merged commit f4294b1 into microsoft:master Aug 28, 2019
@DHowett-MSFT
Copy link
Contributor

Thanks for the contribution, as always! 😄

@ghost
Copy link

ghost commented Sep 24, 2019

🎉Windows Terminal Preview v0.5.2661.0 has been released which incorporates this pull request.:tada:

Handy links:

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.

4 participants