Fix tab completions
This commit is contained in:
parent
4116d08642
commit
a8ac7415f8
4 changed files with 31 additions and 25 deletions
|
@ -68,6 +68,7 @@ const setCommand = (args) => {
|
|||
};
|
||||
};
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
const exec = (tab, line, settings) => {
|
||||
let [name, args] = parsers.parseCommandLine(line);
|
||||
|
||||
|
|
|
@ -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([]);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
|
Reference in a new issue