diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-11 21:32:28 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-11 21:43:23 +0900 |
commit | a28f6f916d77baf87e3c023abbd6494e009a8d12 (patch) | |
tree | 4f619dea6207c1a15833612eec3589a15641c69f /src/background | |
parent | 067da88d06fbffca323ecdbaf8b1011f88225219 (diff) |
Complete console commands
Diffstat (limited to 'src/background')
-rw-r--r-- | src/background/shared/completions/index.js | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index d5875fe..22713e7 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -1,7 +1,19 @@ +import commandDocs from 'shared/commands/docs'; import * as tabs from './tabs'; import * as histories from './histories'; import * as bookmarks from './bookmarks'; +const completeCommands = (typing) => { + let keys = Object.keys(commandDocs); + return keys + .filter(name => name.startsWith(typing)) + .map(name => ({ + caption: name, + content: name, + url: commandDocs[name], + })); +}; + const getSearchCompletions = (command, keywords, searchConfig) => { let engineNames = Object.keys(searchConfig.engines); let engineItems = engineNames.filter(name => name.startsWith(keywords)) @@ -74,20 +86,21 @@ const getBufferCompletions = async(command, keywords, excludePinned) => { ]; }; -const getCompletions = (line, settings) => { - let typedWords = line.trim().split(/ +/); - let typing = ''; - if (!line.endsWith(' ')) { - typing = typedWords.pop(); - } - - if (typedWords.length === 0) { - return Promise.resolve([]); +const complete = (line, settings) => { + let trimmed = line.trimStart(); + let words = trimmed.split(/ +/); + let name = words[0]; + if (words.length === 1) { + return Promise.resolve([ + { + name: 'Console Command', + items: completeCommands(name), + } + ]); } - let name = typedWords.shift(); - let keywords = typedWords.concat(typing).join(' '); + let keywords = trimmed.slice(name.length).trimStart(); - switch (name) { + switch (words[0]) { case 'o': case 'open': case 't': @@ -112,8 +125,4 @@ const getCompletions = (line, settings) => { return Promise.resolve([]); }; -const complete = (line, settings) => { - return getCompletions(line, settings); -}; - export { complete }; |