(direction, { count, tab })
| 438 | |
| 439 | // Remove tabs before, after, or either side of the currently active tab |
| 440 | async 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". |
no test coverage detected