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

Most recently used tab with Ctrl-Tab cycling #4671

Merged
merged 50 commits into from
Oct 7, 2020

Conversation

guifel
Copy link
Contributor

@guifel guifel commented Feb 18, 2020

Resolves brave/brave-browser#913

I implemented MRU cycling feature as requested in the issue. I added a new option under the section Tab "Cycle through the most recently used tabs with Ctrl-Tab" to activate the feature. Deactivated by default.

This is inspired by how MRU cycling is implemented at the ChromeOS level.

Screenshot from 2020-09-27 12-08-46

Submitter Checklist:

Test Plan:

TBD

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@guifel
Copy link
Contributor Author

guifel commented Feb 18, 2020

To do before ready for review:

  • Fix and adapt this for MacOS. I don't have a Mac at the moment, I might get one next week.
  • Add build flags to not apply these changes for iOS and Android
  • Support regular previous/next cycling while using the page up/down keys (Ctrl-Page up/down) when MRU is activated.
  • Figure out the bug with the gtk event loop crashing the browser when spamming keys on the new page tab (Might be unrelated to this)

@guifel guifel closed this Feb 25, 2020
@guifel guifel force-pushed the guifel-1/mru-clycling-ctrl-tab branch from a34b6a7 to 2b0f75c Compare February 25, 2020 12:51
@guifel guifel reopened this Feb 25, 2020
@guifel guifel force-pushed the guifel-1/mru-clycling-ctrl-tab branch 3 times, most recently from 03b4d1c to 4cb05fc Compare February 25, 2020 14:41
@guifel guifel marked this pull request as ready for review February 25, 2020 21:40
@guifel guifel requested a review from bridiver as a code owner February 25, 2020 21:40
@guifel
Copy link
Contributor Author

guifel commented Feb 25, 2020

Ufffff, that was harder than I first expected but I've now implemented everything I wanted :)

First, I am a daily Brave user and what you're doing is awesome. This was my biggest frustration when moving from Firefox so I had a try. It's my first contribution to Brave and experience with the Chromium code base. It is certainly not yet perfect, I need some feedback.

I have build and tested the feature on Linux (Ubuntu), Windows and Mac.

The only missing piece is that Ctrl-Previous and Ctrl-Next are doing MRU switching as well. I originally wanted to do a simple switch to the previous and next tab even when the feature is activated. Unfortunately, Chromium treats Ctrl-Next and Ctrl-Previous the same way as Ctrl-Tab and Ctrl-Maj-Tab down to some quite lower level controllers. If we really need this feature we will have to do some more changes at the Chromium level.

@guifel guifel requested review from petemill and bsclifton February 25, 2020 21:44
@petemill
Copy link
Member

Thank you so much for getting deep in to this issue @guifel and persisting to get it working! I'll definitely review the UX impact and have a go at understanding if we can split the keyboard shortcuts as you mention.

Special thanks for also putting the effort in to do the patching and overrides in a clean way.

@iefremov iefremov self-requested a review February 27, 2020 06:30
int current_mru_cycling_index = -1;

// List of tab indexes sorted by most recently used
std::vector<int> mru_cycle_list;
Copy link
Contributor

Choose a reason for hiding this comment

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

have you checked base::MRUCache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not aware of this class but I am not sure it is a good fit here. I am calculating from scratch the ordered set of tab indices at the beginning of each cycling session with std:sort and the timestamp of last use.
base:MRUCache keeps track of the ordering by calling the Put function whenever the item is used.

To use MRUCache I would need to call Put each time a tab is accessed, not sure this is possible form TabStripModel.

Copy link
Contributor

@kkuehlz kkuehlz Apr 10, 2020

Choose a reason for hiding this comment

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

Hmm. So it looks like that timestamp is being set in TabStripModel::ActivateTabAt. What about overriding that method and calling base::MRUCache.Put when the new tab is activated instead of doing your own MRU?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My problem with base::MRUCache is that it's a map data-structure with key-value pairs. What I need is a simple MRU queue.
Also, I thought that relying on this already existing timestamp would be better than maintaining an additional index.

@guifel guifel requested review from yrliou and iefremov February 27, 2020 15:25
@guifel
Copy link
Contributor Author

guifel commented Mar 7, 2020

@yrliou @iefremov do you have anymore feedback ? Is anything blocking you ?

@Helldembez
Copy link

@guifel You are my hero.

@guifel
Copy link
Contributor Author

guifel commented Mar 7, 2020

Thanks @Helldembez 🤣 but the PR is not yet merged. Brave team seems busy.

@bsclifton
Copy link
Member

bsclifton commented Mar 7, 2020

@guifel do you think you can give this a rebase and squash the commits up a bit? I wouldn't squash into one commit, but try to group similar ones together (ex: where you fix review feedback). Let me know if you need help with that 😄

And huge thanks for submitting this- we'll definitely work with you to get it merged 😄

@guifel guifel force-pushed the guifel-1/mru-clycling-ctrl-tab branch 4 times, most recently from cd290d8 to 3c842c9 Compare March 9, 2020 11:03
@guifel
Copy link
Contributor Author

guifel commented Mar 9, 2020

@bsclifton done. In the first commit I add the toggle button in the settings (which touches many files..) and in the second commit we have the core logic of the MRU tab switch. The 2 last commits are the requested changes by @yrliou and @iefremov.

@simonhong simonhong force-pushed the guifel-1/mru-clycling-ctrl-tab branch from 28da6b5 to 9a91afa Compare October 7, 2020 04:46
@simonhong simonhong merged commit c15b8ce into brave:master Oct 7, 2020
@simonhong
Copy link
Member

@guifel, Finally merged! 🎉

@guifel
Copy link
Contributor Author

guifel commented Oct 7, 2020

Awesome to see this feature in the master! Thank you guys for the amazing job.

@bsclifton
Copy link
Member

@guifel thanks for your contribution and also your patience 😄 This is a great feature!
@simonhong thanks for championing this (rebasing, fixing items, etc) and taking it across the finish line

This should be in Nightly in the next day or so 😄

@rjshrjndrn
Copy link

woohoo at last... Here comes Brave With C-Tab

@kindrowboat
Copy link

FYI: I have submitted an issue to Chromium to consider merging/cherry-picking these commits into Chromium. https://bugs.chromium.org/p/chromium/issues/detail?id=1150395

@bsclifton
Copy link
Member

@motevets awesome, thanks! That would be a great one to upstream

@believerd
Copy link

Hi developer, there seems to be a bug in the MRU implementation. If you open just one new tab using open link in new tab(right click) then Ctrl-Tab won't work.

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.

Ctrl-tab to switch from most-to-least recently used tab