MCPcopy Index your code
hub / github.com/philc/vimium / selectTab

Function selectTab

background_scripts/main.js:469–487  ·  view source on GitHub ↗
(direction, { count, tab })

Source from the content-addressed store, hash-verified

467// Selects a tab before or after the currently selected tab.
468// - direction: "next", "previous", "first" or "last".
469function selectTab(direction, { count, tab }) {
470 chrome.tabs.query(visibleTabsQueryArgs, function (tabs) {
471 if (tabs.length > 1) {
472 const toSelect = (() => {
473 switch (direction) {
474 case "next":
475 return (getTabIndex(tab, tabs) + count) % tabs.length;
476 case "previous":
477 return ((getTabIndex(tab, tabs) - count) + (count * tabs.length)) % tabs.length;
478 case "first":
479 return Math.min(tabs.length - 1, count - 1);
480 case "last":
481 return Math.max(0, tabs.length - count);
482 }
483 })();
484 chrome.tabs.update(tabs[toSelect].id, { active: true });
485 }
486 });
487}
488
489chrome.webNavigation.onCommitted.addListener(async ({ tabId, frameId }) => {
490 // Vimium can't run on all tabs (e.g. chrome:// URLs). insertCSS will throw an error on such tabs,

Callers 4

nextTabFunction · 0.85
previousTabFunction · 0.85
firstTabFunction · 0.85
lastTabFunction · 0.85

Calls 2

getTabIndexFunction · 0.85
updateMethod · 0.80

Tested by

no test coverage detected