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

Focus tab if existing for bookmarks & history #92

Merged
merged 2 commits into from Jan 5, 2019

Conversation

mattcompiles
Copy link
Contributor

Type of Change

  • Bugfix/Cleanup (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Summary Of Changes

This change makes saka focus any existing tabs that match the URL for bookmarks & history searches, falling back to creating a new tab if none are found.

Why is this change needed?

Love the extension and I have been using it for quite a while now. I primarily use it for bookmark searching which is my default mode (although I'd love to have a unified search mode!). I commonly open bookmarks that I already have open in an active tab which will then open a new tab. I find this annoying as I end up with multiple of the same page open.

I think this change is the ideal behaviour but happy to discuss.

Does this close any open issues?

No

Checklist

  • Tests are passing locally

@codecov-io
Copy link

codecov-io commented Jan 3, 2019

Codecov Report

Merging #92 into master will increase coverage by 0.35%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #92      +/-   ##
==========================================
+ Coverage    57.9%   58.26%   +0.35%     
==========================================
  Files          58       58              
  Lines         708      714       +6     
  Branches       65       65              
==========================================
+ Hits          410      416       +6     
  Misses        267      267              
  Partials       31       31
Impacted Files Coverage Δ
src/suggestion_engine/server/index.js 95.23% <100%> (+1.9%) ⬆️

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 ef0b7bc...1eb7a80. Read the comment docs.

@pureooze
Copy link
Member

pureooze commented Jan 4, 2019

Thanks for creating a PR for this! I think the change is helpful and we can definitely update the behavior.

Saka currently kind of has a global search in the Recently Viewed mode. However this leaves the bookmarks out of the results. Maybe that can be changed (with the mode name updated) so that bookmarks are also included.

Copy link
Member

@pureooze pureooze left a comment

Choose a reason for hiding this comment

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

There are some small changes I suggested but overall it looks great! Let me know if you have any questions about what I suggested.

await browser.tabs.update(existingTab.id, { active: true });
await browser.windows.update(existingTab.windowId, { focused: true });
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Small thing but I would prefer getting rid of the return and placing the await statement in an else block here.

@@ -63,6 +63,24 @@ test('should call appropriate activation methods', async () => {
expect(browser.tabs.update.calledOnce).toEqual(true);
});

test('should focus bookmark and history tabs if already open', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Awesome! 🎉

@@ -63,6 +63,24 @@ test('should call appropriate activation methods', async () => {
expect(browser.tabs.update.calledOnce).toEqual(true);
});

test('should focus bookmark and history tabs if already open', async () => {
browser.flush();
browser.tabs.query.returns(Promise.resolve([{ id: '1', windowId: '1' }]));
Copy link
Member

Choose a reason for hiding this comment

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

Minor thing but I think there is a browser.tabs.query.yields API that lets you avoid having to use the Promise API directly. Might be wrong about this but I remember seeing it before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like stub.resolves is the correct API. Update incoming.

test('should focus bookmark and history tabs if already open', async () => {
browser.flush();
browser.tabs.query.returns(Promise.resolve([{ id: '1', windowId: '1' }]));
await activateSuggestion({
Copy link
Member

Choose a reason for hiding this comment

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

Can the tests in the previous test ('should call appropriate activation methods') for the bookmark and history mode be deleted since we have coverage from these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous tests ensure that the "create a new tab" behaviour still occurs when no existing tabs are open. It's a little unclear that this is the case though. I didn't want to change the file too much as it's my first PR to this repo.

@mattcompiles
Copy link
Contributor Author

Feedback addressed.

Would be really interested in the combined search mode including bookmarks. Happy to chat or help out if need be 👍

Copy link
Member

@pureooze pureooze left a comment

Choose a reason for hiding this comment

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

LGTM!

Lets create a new issue to track the work required for adding the bookmark search results to a global search mode.

@pureooze pureooze merged commit e7c37da into lusakasa:master Jan 5, 2019
@pureooze pureooze mentioned this pull request Jan 6, 2019
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.

None yet

3 participants