Skip to content

Commit 40f662d

Browse files
kain-tmNikolay Sezganov
andauthored
feat: add close tabs by URL with ;x (#2415)
Open filtered tab list with URLs stripped of query params, Enter closes all visible tabs at once. Uses omnibar with pagination support. Co-authored-by: Nikolay Sezganov <nikolay.sezganov@aspose.com>
1 parent a72fbdd commit 40f662d

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/background/start.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ function start(browser) {
839839
});
840840
});
841841
};
842+
self.closeTabByIds = function(message, sender, sendResponse) {
843+
chrome.tabs.remove(message.tabIds);
844+
};
842845
function focusTab(windowId, tabId) {
843846
chrome.windows.update(windowId, {
844847
focused: true

src/content_scripts/common/default.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,9 @@ export default function(api, clipboard, insert, normal, hints, visual, front, br
844844
mapkey('b', '#8Open a bookmark', function() {
845845
front.openOmnibar(({type: "Bookmarks"}));
846846
});
847+
mapkey(';x', '#3Close tabs by URL', function() {
848+
front.openOmnibar({type: "CloseTabs"});
849+
});
847850
mapkey('ab', '#8Bookmark current page to selected folder', function() {
848851
var page = {
849852
url: window.location.href,

src/content_scripts/ui/omnibar.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ function createOmnibar(front, clipboard) {
764764
});
765765
}));
766766
self.addHandler('Tabs', OpenTabs(self));
767+
self.addHandler('CloseTabs', CloseTabs(self));
767768
self.addHandler('Windows', OpenWindows(self, front));
768769
self.addHandler('VIMarks', OpenVIMarks(self));
769770
self.addHandler('SearchEngine', searchEngine);
@@ -1120,6 +1121,49 @@ function OpenTabs(omnibar) {
11201121
return self;
11211122
}
11221123

1124+
function CloseTabs(omnibar) {
1125+
var self = {
1126+
focusFirstCandidate: true,
1127+
};
1128+
1129+
self.onOpen = function() {
1130+
self.prompt = `close tabs${separatorHtml}`;
1131+
omnibar.cachedPromise = new Promise(function(resolve) {
1132+
RUNTIME('getTabs', {queryInfo: {currentWindow: true}}, function(response) {
1133+
resolve(response.tabs);
1134+
});
1135+
});
1136+
self.onInput();
1137+
};
1138+
self.onInput = function() {
1139+
omnibar.cachedPromise.then(function(cached) {
1140+
var filtered = filterByTitleOrUrl(cached, omnibar.input.value, runtime.getCaseSensitive(omnibar.input.value));
1141+
filtered.forEach(function(tab) {
1142+
try {
1143+
var u = new URL(tab.url);
1144+
tab.url = u.origin + u.pathname;
1145+
} catch (e) {}
1146+
});
1147+
omnibar.listURLs(filtered, false);
1148+
});
1149+
};
1150+
self.onEnter = function() {
1151+
var items = omnibar.resultsDiv.querySelectorAll('#sk_omnibarSearchResult>ul>li');
1152+
var tabIds = [];
1153+
items.forEach(function(li) {
1154+
if (li.uid && li.uid[0] === 'T') {
1155+
var parts = li.uid.substr(1).split(":");
1156+
tabIds.push(parseInt(parts[1]));
1157+
}
1158+
});
1159+
if (tabIds.length > 0) {
1160+
RUNTIME('closeTabByIds', {tabIds: tabIds});
1161+
}
1162+
return true;
1163+
};
1164+
return self;
1165+
}
1166+
11231167
function OpenWindows(omnibar, front) {
11241168
const self = {
11251169
prompt: `Move current tab to window${separatorHtml}`

0 commit comments

Comments
 (0)