Get completion items as Promises
This commit is contained in:
parent
104a9666ff
commit
76e09c7512
1 changed files with 19 additions and 8 deletions
|
@ -1,22 +1,33 @@
|
|||
import * as tabs from './tabs';
|
||||
import * as histories from './histories';
|
||||
|
||||
const getOpenCompletions = (command, keywords, searchConfig) => {
|
||||
const getSearchCompletions = (command, keywords, searchConfig) => {
|
||||
let engineNames = Object.keys(searchConfig.engines);
|
||||
let engineItems = engineNames.filter(name => name.startsWith(keywords))
|
||||
.map(name => ({
|
||||
caption: name,
|
||||
content: command + ' ' + name
|
||||
}));
|
||||
return Promise.resolve(engineItems);
|
||||
};
|
||||
|
||||
const getHistoryCompletions = (command, keywords) => {
|
||||
return histories.getCompletions(keywords).then((pages) => {
|
||||
let historyItems = pages.map((page) => {
|
||||
return pages.map((page) => {
|
||||
return {
|
||||
caption: page.title,
|
||||
content: command + ' ' + page.url,
|
||||
url: page.url
|
||||
};
|
||||
});
|
||||
let engineNames = Object.keys(searchConfig.engines);
|
||||
let engineItems = engineNames.filter(name => name.startsWith(keywords))
|
||||
.map(name => ({
|
||||
caption: name,
|
||||
content: command + ' ' + name
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
const getOpenCompletions = (command, keywords, searchConfig) => {
|
||||
return Promise.all([
|
||||
getSearchCompletions(command, keywords, searchConfig),
|
||||
getHistoryCompletions(command, keywords),
|
||||
]).then(([engineItems, historyItems]) => {
|
||||
let completions = [];
|
||||
if (engineItems.length > 0) {
|
||||
completions.push({
|
||||
|
|
Reference in a new issue