diff options
-rw-r--r-- | src/background/actions/command.js | 1 | ||||
-rw-r--r-- | src/background/shared/completions/index.js | 46 | ||||
-rw-r--r-- | src/background/shared/completions/tabs.js | 4 | ||||
-rw-r--r-- | src/background/shared/tabs.js | 5 |
4 files changed, 31 insertions, 25 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js index 888b46f..39e880d 100644 --- a/src/background/actions/command.js +++ b/src/background/actions/command.js @@ -68,6 +68,7 @@ const setCommand = (args) => { }; }; +// eslint-disable-next-line complexity const exec = (tab, line, settings) => { let [name, args] = parsers.parseCommandLine(line); diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index 21c3dd2..728cee7 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -65,6 +65,25 @@ const getOpenCompletions = (command, keywords, searchConfig) => { }); }; +const getBufferCompletions = (command, keywords, excludePinned) => { + return tabs.getCompletions(keywords, excludePinned).then((got) => { + let items = got.map((tab) => { + return { + caption: tab.title, + content: command + ' ' + tab.title, + url: tab.url, + icon: tab.favIconUrl + }; + }); + return [ + { + name: 'Buffers', + items: items + } + ]; + }); +}; + const getCompletions = (line, settings) => { let typedWords = line.trim().split(/ +/); let typing = ''; @@ -88,30 +107,17 @@ const getCompletions = (line, settings) => { return getOpenCompletions(name, keywords, settings.search); case 'b': case 'buffer': - case 'bd': - case 'bdel': - case 'bdelete': + return getBufferCompletions(name, keywords, false); case 'bd!': case 'bdel!': case 'bdelete!': - case 'bdeletes': case 'bdeletes!': - return tabs.getCompletions(keywords).then((gotTabs) => { - let items = gotTabs.map((tab) => { - return { - caption: tab.title, - content: name + ' ' + tab.title, - url: tab.url, - icon: tab.favIconUrl - }; - }); - return [ - { - name: 'Buffers', - items: items - } - ]; - }); + return getBufferCompletions(name, keywords, false); + case 'bd': + case 'bdel': + case 'bdelete': + case 'bdeletes': + return getBufferCompletions(name, keywords, true); } return Promise.resolve([]); }; diff --git a/src/background/shared/completions/tabs.js b/src/background/shared/completions/tabs.js index 5edddca..8c0f1f9 100644 --- a/src/background/shared/completions/tabs.js +++ b/src/background/shared/completions/tabs.js @@ -1,7 +1,9 @@ -const getCompletions = (keyword) => { +const getCompletions = (keyword, excludePinned) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => { let matched = tabs.filter((t) => { return t.url.includes(keyword) || t.title && t.title.includes(keyword); + }).filter((t) => { + return !(excludePinned && t.pinned); }); return matched; }); diff --git a/src/background/shared/tabs.js b/src/background/shared/tabs.js index a9a677a..d09f676 100644 --- a/src/background/shared/tabs.js +++ b/src/background/shared/tabs.js @@ -16,16 +16,13 @@ const closeTabByKeywords = (keyword) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => { let matched = tabs.filter((t) => { return t.url.includes(keyword) || t.title.includes(keyword); - }); + }).filter(t => !t.pinned); if (matched.length === 0) { throw new Error('No matching buffer for ' + keyword); } else if (matched.length > 1) { throw new Error('More than one match for ' + keyword); } - if (matched[0].pinned) { - throw new Error('Cannot close a pinned tab (add ! to override)'); - } browser.tabs.remove(matched[0].id); }); }; |