Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Enable use of middle click to close tabs #2190

Merged
merged 15 commits into from
May 16, 2018
Merged

Enable use of middle click to close tabs #2190

merged 15 commits into from
May 16, 2018

Conversation

texhnolyze
Copy link
Contributor

Enables closing oni tabs with middle click, much like e.g. firefox/chrome.
Corresponds to #2069.

Do not merge yet:
As mentioned in the issue there is still some clarification needed
concerning the ability to close tabs, when only a single one is opened and how to go
about testing clicks/middle clicks of tabs to ensure they are correctly selected and closed.

@keforbes
Copy link
Collaborator

keforbes commented May 10, 2018

Do not merge yet:

Please put [WIP] (Work In Progress) at the beginning of the Pull Request's title until the Pull Request is ready.

@keforbes keforbes changed the title Enable use of middle click to close tabs [WIP] Enable use of middle click to close tabs May 10, 2018
@keforbes
Copy link
Collaborator

Feel free to edit the title and remove [WIP] when you're ready to go. 🙂

@bryphe
Copy link
Member

bryphe commented May 11, 2018

Thank you for the PR, @texhnolyze ! The functionality change looks great to me 👍

Would it be possible to add a test case to exercise this behavior? I'm wondering if we could use the simulate method to exercise the normal click and non-middle button click, and check if the correct onTabClosed and onTabSelect callbacks from the props are executed as expected?

EDIT: Sorry I should've read the PR description, sounds like you were already thinking about this 😄 Awesome!

As mentioned in the issue there is still some clarification needed
concerning the ability to close tabs, when only a single one is opened

As long as the middle-click behaves the same as clicking the 'x' in this case, that should be fine for this change IMO. We could track changes to improving the onTabClose behavior when there is a single tab in a separate PR.

@texhnolyze
Copy link
Contributor Author

@keforbes thanks, will do in the future
@bryphe ok once I am finished with this I will open a new issue concerning the single tab behaviour.
Concerning the test I will have another try to get that working, however due to the the async nature of FileIcon (as described in the issue) the way I see it the only two ways to get that test working is injecting FileIcon as a dependency so that I can mock it out in the test easily (which would require quite a bit of change), overwriting the actual imported FileIcon in tabs or actually setup the underlying async IconThemes first and turn the test more into an integration test. Not sure what the best option would be.

and write own @types module declaration so that it can be used in
testing nstead of using a mock. The mock does not suffice as the
way the actual module previously had to be imported was
"import * as classNames" where classNames was the actual function.

It is not possible to build a module in typescript/es6 imports, which
will directly return a function in the same way the dependency did
in commonjs module syntax. Instead when defining a function to be
returned as default export it is returned as an Object like this
"{ default: [Function] }", which is correctly resolved when importing
with "import classNames from 'classnames'".

This only previously worked in production as webpacks ts-loader,
handles this issue, whereas when testing the sources are only compiled
with tsc.

There is an update to the classnames dependency on the current master,
but there hasn't been a release since 2006. So options were to setup
webpack for tests as well or add updated classnames dependency which
sets a "default" value on its commonjs exports.

Links for reference:
JedWatson/classnames#152
JedWatson/classnames#106
DefinitelyTyped/DefinitelyTyped#25206
microsoft/TypeScript#2719
@codecov
Copy link

codecov bot commented May 15, 2018

Codecov Report

Merging #2190 into master will decrease coverage by <.01%.
The diff coverage is 9.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2190      +/-   ##
==========================================
- Coverage   37.14%   37.13%   -0.01%     
==========================================
  Files         296      296              
  Lines       12137    12138       +1     
  Branches     1597     1599       +2     
==========================================
  Hits         4508     4508              
- Misses       7378     7379       +1     
  Partials      251      251
Impacted Files Coverage Δ
browser/src/UI/components/Tabs.tsx 31.68% <9.09%> (-0.32%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bfd84e6...8d8d4dd. Read the comment docs.

clickedTab
.find(".corner")
.first()
.simulate("mouseDown", { button: 1 })
Copy link
Member

Choose a reason for hiding this comment

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

Wow, thanks for figuring out how to exercise this @texhnolyze 💯

@bryphe
Copy link
Member

bryphe commented May 15, 2018

@texhnolyze - sorry for the late response - thanks for expanding the test coverage! I'm glad you found a way to mock the FileIcon and Sneakable 👍 Change looks great to me, I'm glad we have that functionality covered / protected now.

I'm ready to bring this in when you are - let me know if it's good to go. Thanks again!

@texhnolyze
Copy link
Contributor Author

@bryphe yeah took my some trial and error, but this is finished from my side for this pull request, if you already had a look at the changes you probably saw what I did with the classnames dependency (commit).

This works for now, but I would suggest maybe dropping the dependency in favor of an own implementation, because as it currently stands it does not seem like there will be a new release soon. The implementation of this as a project component should be failrly trivial. What do you think?

Also now that I know a bit more about the test setup and jest and so on, I'll do a pull request, when I find the time, to add a bit more test coverage and to get to know the code base better.

@texhnolyze texhnolyze changed the title [WIP] Enable use of middle click to close tabs Enable use of middle click to close tabs May 16, 2018
@bryphe
Copy link
Member

bryphe commented May 16, 2018

@bryphe yeah took my some trial and error, but this is finished from my side for this pull request, if you already had a look at the changes you probably saw what I did with the classnames dependency (commit).

Thanks for calling this out!

This works for now, but I would suggest maybe dropping the dependency in favor of an own implementation, because as it currently stands it does not seem like there will be a new release soon. The implementation of this as a project component should be failrly trivial. What do you think?

Yes, it seems reasonable to me for now, but as you mentioned, I think long-term it makes sense to move away from this. With the direction the codebase is moving, I think, instead of using css classes directly, we could refactor those classes to use styled-components, and move the styling into a styled-component, and remove our css. @Akin909 got us set up with styled-components, and @cryza has done work to migrate some of our existing components over (#1980, #1991), so they might have ideas too. 👍

Also now that I know a bit more about the test setup and jest and so on, I'll do a pull request, when I find the time, to add a bit more test coverage and to get to know the code base better.

Awesome! That would be great 💯 Really appreciate the help!

@bryphe bryphe merged commit 94d6cbf into onivim:master May 16, 2018
@bryphe
Copy link
Member

bryphe commented May 16, 2018

Merged - thank you for the contribution, @texhnolyze ! 💯

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants