MCPcopy
hub / github.com/philc/vimium / removeTabsRelative

Function removeTabsRelative

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

Source from the content-addressed store, hash-verified

438
439// Remove tabs before, after, or either side of the currently active tab
440async function removeTabsRelative(direction, { count, tab }) {
441 // count is null if the user didn't type a count prefix before issuing this command and didn't
442 // specify a count=n option in their keymapping settings. Interpret this as closing all tabs on
443 // either side.
444 if (count == null) count = 99999;
445 const activeTab = tab;
446 const tabs = await chrome.tabs.query(visibleTabsQueryArgs);
447 const activeIndex = getTabIndex(activeTab, tabs);
448 const toRemove = tabs.filter((tab, tabIndex) => {
449 if (tab.pinned || tab.id == activeTab.id) {
450 return false;
451 }
452 switch (direction) {
453 case "before":
454 return tabIndex < activeIndex &&
455 tabIndex >= activeIndex - count;
456 case "after":
457 return tabIndex > activeIndex &&
458 tabIndex <= activeIndex + count;
459 case "both":
460 return true;
461 }
462 });
463
464 await chrome.tabs.remove(toRemove.map((t) => t.id));
465}
466
467// Selects a tab before or after the currently selected tab.
468// - direction: "next", "previous", "first" or "last".

Callers 3

closeTabsOnLeftFunction · 0.85
closeTabsOnRightFunction · 0.85
closeOtherTabsFunction · 0.85

Calls 3

getTabIndexFunction · 0.85
removeMethod · 0.80
filterMethod · 0.45

Tested by

no test coverage detected