diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-18 21:59:39 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-18 21:59:39 +0900 |
commit | c4e79243ca18275e223e1ae405b9ad4b466c918d (patch) | |
tree | 66dcd5c777a0f0bf6834f9e2e665a95fcd16d717 /src/actions | |
parent | 0e924a27d1fee402312e40f3cba978e1adb20661 (diff) |
completion for search engines
Diffstat (limited to 'src/actions')
-rw-r--r-- | src/actions/command.js | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/src/actions/command.js b/src/actions/command.js index 022e4f6..93c06b8 100644 --- a/src/actions/command.js +++ b/src/actions/command.js @@ -63,6 +63,39 @@ const bufferCommand = (keywords) => { }); }; +const getOpenCompletions = (keywords) => { + return histories.getCompletions(keywords).then((pages) => { + let historyItems = pages.map((page) => { + return { + caption: page.title, + content: page.url, + url: page.url + }; + }); + let engineNames = Object.keys(DEFAULT_SEARCH_ENGINES.engines); + let engineItems = engineNames.filter(name => name.startsWith(keywords)) + .map(name => ({ + caption: name, + content: name + })); + + let completions = []; + if (engineItems.length > 0) { + completions.push({ + name: 'Search Engines', + items: engineItems + }); + } + if (historyItems.length > 0) { + completions.push({ + name: 'History', + items: historyItems + }); + } + return completions; + }); +}; + const doCommand = (name, remaining) => { switch (name) { case 'o': @@ -85,21 +118,7 @@ const getCompletions = (command, keywords) => { case 'open': case 't': case 'tabopen': - return histories.getCompletions(keywords).then((pages) => { - let items = pages.map((page) => { - return { - caption: page.title, - content: page.url, - url: page.url - }; - }); - return [ - { - name: 'History', - items - } - ]; - }); + return getOpenCompletions(keywords); case 'b': case 'buffer': return tabs.getCompletions(keywords).then((gotTabs) => { |