diff options
| author | Stephen Blott | 2016-09-14 06:10:08 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-09-14 06:10:08 +0100 |
| commit | fd20405ddf27365cfaf69e16289b2fc6d39c2a5e (patch) | |
| tree | 62044c33f016acfa47a84b56e92b9639b33f58e0 | |
| parent | 0006776fecdd5eb02da8973ae6856824c090c82e (diff) | |
| download | vimium-fd20405ddf27365cfaf69e16289b2fc6d39c2a5e.tar.bz2 | |
Match globa-mark URLs by length.
This changes the logic for selecting an existing tab when using global marks.
Previously, an exact RUL match was required. Here, we only require a prefix match.
For example, if the global-mark URL is:
https://inbox.google.com/u/0/
Then a tab with the URL
https://inbox.google.com/u/0/sent
will be selected.
This is a more usable approach when the user uses global marks to visit
important sites like gmail, Facebook or Twitter. On these sites, the
URL changes, but the user still thinks of the tab as their "gmail tab",
for example.
Also, when choosing between multiple candidate tabs:
- If there is at least one candidate in the current window, then only consider candidates in the current window.
- If there are more than one candidates, then don't select the current tab.
- Finally, select the remaining candidate with the shortest URL.
Closes #2248.
| -rw-r--r-- | background_scripts/marks.coffee | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee index 8fe30b2f..29029b4d 100644 --- a/background_scripts/marks.coffee +++ b/background_scripts/marks.coffee @@ -63,10 +63,10 @@ Marks = # The tab we're trying to find no longer exists. We either find another tab with a matching URL and use it, # or we create a new tab. focusOrLaunch: (markInfo, req) -> - chrome.tabs.query { url: markInfo.url }, (tabs) => + chrome.tabs.query { url: "#{markInfo.url}*" }, (tabs) => if 0 < tabs.length - # We have a matching tab: use it (prefering, if there are more than one, one in the current window). - @pickTabInWindow tabs, (tab) => + # We have at least one matching tab. Pick one and go to it. + @pickTab tabs, (tab) => @gotoPositionInTab extend markInfo, tabId: tab.id else # There is no existing matching tab, we'll have to create one. @@ -75,11 +75,18 @@ Marks = # is loaded, its DOM is ready and it registers with the background page. tabLoadedHandlers[tab.id] = => @gotoPositionInTab extend markInfo, tabId: tab.id - # Given a list of tabs, pick one in the current window, if possible, otherwise just pick any. - pickTabInWindow: (tabs, continuation) -> + # Given a list of tabs candidate tabs, pick one. Prefer tabs in the current window and tabs with shorter + # (matching) URLs. + pickTab: (tabs, callback) -> chrome.windows.getCurrent ({ id }) -> + # Prefer tabs in the current window, if there are any. tabsInWindow = tabs.filter (tab) -> tab.windowId == id - continuation tabsInWindow[0] ? tabs[0] + tabs = tabsInWindow if 0 < tabsInWindow.length + # If more than one tab remains and the current tab remains a conadidate, then pick another one. + tabs = (tab for tab in tabs when not tab.active) if 1 < tabs.length + # Prefer shorter URLs. + tabs.sort (a,b) -> a.url.length - b.url.length + callback tabs[0] root = exports ? window root.Marks = Marks |
