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

Use a stack to keep track of the previous tabs and find the most recently opened one #44

Closed
carbon-steel opened this issue Jun 10, 2017 · 0 comments

Comments

@carbon-steel
Copy link
Collaborator

Something I think we can improve on this "go to last tab" feature is to avoid having it do nothing. Right now, if we go from tab A to tab B and then close tab A, using the "go to last tab" feature will not do anything.

Solution

I think one clean solution that will fix all of the issues mentioned here and in other issues ( #30 , #14 , #32 , #39 ) is to use a stack to keep track of the previous pages in the background script. Basically, we keep track of a variable called current_tab_id and, every time a new tab becomes active, we push (the now outdated) current_tab_id onto the stack (we can limit the size of the stack to avoid memory issues) and update current_tab_id to the value of the new tab's id. This way, when the "go to last tab" command is called, the background script just keeps popping off the stack until it finds a tab that is not the current tab and is not closed (and then it updates the stack because it will move to a new tab).

That way, if we are in the hotkey flow of tab search, then we'll be able to go to the correct previous tab because the "tab search tab" will have been closed whether or not you use the "tab search page" or just close it.

Benefits of doing this

  • We don't need search_launch_tab_id anymore
  • openTabSearch() can be simplified
  • During the Hotkey flow of the "search tabs" functionality, we don't have to switch to the previous tab and the navigate to the new one anymore (because this makes the code kind of obscure).
  • We no longer need to check if a search is occurring from a tab or from a popup
  • The popup does not need to exchange messages with the background script and we can decouple the two (which is always good from a development standpoint).
  • The use of the stack makes our code more concise and to the point

Overall, I think this is a better way because it simplifies the logic (fewer if conditionals), is more expressive, can do more, decouples the popup from the background script, and makes the code easier to read.

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

No branches or pull requests

2 participants