aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-05-10 21:56:49 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-05-12 09:10:18 +0900
commitc4fb6f01319ca2d0cb71da2f3ed41de1ff35130c (patch)
tree237ca880baa2dad23be87293102c3a3f5b4ed4b6
parentb0dddc9fa7765dc252fd11fc7d0fe52820655fd5 (diff)
Add :bdeletes command
-rw-r--r--src/background/actions/command.js2
-rw-r--r--src/background/shared/completions/index.js1
-rw-r--r--src/background/shared/tabs.js10
3 files changed, 12 insertions, 1 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js
index 2b77507..020a57f 100644
--- a/src/background/actions/command.js
+++ b/src/background/actions/command.js
@@ -84,6 +84,8 @@ const exec = (tab, line, settings) => {
case 'b':
case 'buffer':
return bufferCommand(args);
+ case 'bdeletes':
+ return tabs.closeTabsByKeywords(args.join(' '));
case 'addbookmark':
return addBookmarkCommand(tab, args).then((item) => {
if (!item) {
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js
index 8ecdcfc..43af23d 100644
--- a/src/background/shared/completions/index.js
+++ b/src/background/shared/completions/index.js
@@ -88,6 +88,7 @@ const getCompletions = (line, settings) => {
return getOpenCompletions(name, keywords, settings.search);
case 'b':
case 'buffer':
+ case 'bdeletes':
return tabs.getCompletions(keywords).then((gotTabs) => {
let items = gotTabs.map((tab) => {
return {
diff --git a/src/background/shared/tabs.js b/src/background/shared/tabs.js
index f1dcc73..1e5e3e4 100644
--- a/src/background/shared/tabs.js
+++ b/src/background/shared/tabs.js
@@ -1,3 +1,5 @@
+import * as tabCompletions from './completions/tabs';
+
const closeTab = (id) => {
return browser.tabs.get(id).then((tab) => {
if (!tab.pinned) {
@@ -10,6 +12,12 @@ const closeTabForce = (id) => {
return browser.tabs.remove(id);
};
+const closeTabsByKeywords = (keyword) => {
+ tabCompletions.getCompletions(keyword).then((tabs) => {
+ browser.tabs.remove(tabs.map(tab => tab.id));
+ });
+};
+
const reopenTab = () => {
return browser.sessions.getRecentlyClosed({
maxResults: 1
@@ -119,7 +127,7 @@ const duplicate = (id) => {
};
export {
- closeTab, closeTabForce, reopenTab, selectAt, selectByKeyword,
+ closeTab, closeTabForce, closeTabsByKeywords, reopenTab, selectAt, selectByKeyword,
selectPrevTab, selectNextTab, selectFirstTab,
selectLastTab, selectTab, reload, updateTabPinned,
toggleTabPinned, duplicate