aboutsummaryrefslogtreecommitdiff
path: root/src/background/shared/completions
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/shared/completions')
-rw-r--r--src/background/shared/completions/index.js46
-rw-r--r--src/background/shared/completions/tabs.js4
2 files changed, 33 insertions, 17 deletions
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js
index 8ecdcfc..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,22 +107,17 @@ const getCompletions = (line, settings) => {
return getOpenCompletions(name, keywords, settings.search);
case 'b':
case 'buffer':
- 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, 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;
});