diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-05-06 22:00:23 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-05-06 22:00:23 +0900 |
commit | 76e09c75127d86f4d32cb7fb31ffefc3fc021997 (patch) | |
tree | b62972b177be8299de56a9b3dd7a8c4b0bbb4034 /src/background/shared/completions | |
parent | 104a9666ff627b11ce7cf3a5bf096b1bc3437bc1 (diff) |
Get completion items as Promises
Diffstat (limited to 'src/background/shared/completions')
-rw-r--r-- | src/background/shared/completions/index.js | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index 73b7b27..5bfdbfb 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -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({ |