Skip to content

Commit

Permalink
Merge pull request #3 from xennygrimmato/develop
Browse files Browse the repository at this point in the history
Group tabs when user finds them by title
  • Loading branch information
xennygrimmato authored Jul 4, 2020
2 parents 515b8fd + 0924e09 commit 7fb8592
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
40 changes: 40 additions & 0 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,43 @@ export function openTabWithText(windowId, text) {
chrome.tabs.update(tabs[goodIdx].id, { active: true });
});
}

// groupTabsWithTitle finds all the tabs matching the given title and groups them together.
// TODO(abansal4032): List the matches and let the user select which one to open.
export function groupTabsWithTitle(windowId, title) {
chrome.tabs.query({windowId: windowId}, tabs => {
let matchingIds = [];
for (const tab of tabs) {
if (tab.title === undefined) {
console.log(tab.index);
continue;
}
if (tab.title.toLowerCase().includes(title.toLowerCase())) {
matchingIds.push(tab.id);
}
console.log(tab.title, tab.url);
}
console.log("matchingIds", matchingIds);
// Move the matching tabs to the end and highlight the tabs
chrome.tabs.move(matchingIds, {'windowId': windowId, 'index': -1});
// Refetch the matching tabs for getting the updated indices to highlight.
// Can refactor here.
chrome.tabs.query({windowId: windowId}, tabs => {
let matchingIdxs = [];
for (const tab of tabs) {
if (tab.title === undefined) {
console.log(tab.index);
continue;
}
if (tab.title.toLowerCase().includes(title.toLowerCase())) {
matchingIdxs.push(tab.index);
}
console.log(tab.title, tab.url);
}
console.log("matchingIdxs", matchingIdxs);
if (matchingIds.length != 0) {
chrome.tabs.highlight({'tabs': matchingIdxs});
}
});
});
}
5 changes: 2 additions & 3 deletions src/js/plugins/tab.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { performActionWithDelay, openTabWithText } from '../core';
import { performActionWithDelay, openTabWithText, groupTabsWithTitle } from '../core';



Expand Down Expand Up @@ -317,9 +317,8 @@ const commands = [
action: 'TABS_FIND_TAB',
callback: query => {
console.log(query);
// chrome.tabs.update(tabs[0].id, { active: true });
chrome.windows.getCurrent({}, window => {
openTabWithText(window.id, query);
groupTabsWithTitle(window.id, query);
});
}
},
Expand Down

0 comments on commit 7fb8592

Please sign in to comment.