From a28f6f916d77baf87e3c023abbd6494e009a8d12 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 11 Jul 2018 21:32:28 +0900 Subject: Complete console commands --- src/background/shared/completions/index.js | 41 ++++++++++++++++++------------ 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'src/background/shared/completions') 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 }; -- cgit v1.2.3 From 1e39fed6183bf3b10f48eb52868bb5ab3fe3134f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 11 Jul 2018 21:58:41 +0900 Subject: Complete set commands --- src/background/shared/completions/index.js | 37 ++++++++++++++++++++++++++++++ src/shared/settings/properties.js | 8 ++++++- 2 files changed, 44 insertions(+), 1 deletion(-) (limited to 'src/background/shared/completions') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index 22713e7..d630f33 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -2,6 +2,7 @@ import commandDocs from 'shared/commands/docs'; import * as tabs from './tabs'; import * as histories from './histories'; import * as bookmarks from './bookmarks'; +import * as properties from 'shared/settings/properties'; const completeCommands = (typing) => { let keys = Object.keys(commandDocs); @@ -86,6 +87,40 @@ const getBufferCompletions = async(command, keywords, excludePinned) => { ]; }; +const getSetCompletions = (command, keywords) => { + let keys = Object.keys(properties.docs).filter( + name => name.startsWith(keywords) + ); + let items = keys.map((key) => { + if (properties.types[key] === 'boolean') { + return [ + { + caption: key, + content: command + ' ' + key, + url: 'Enable ' + properties.docs[key], + }, { + caption: 'no' + key, + content: command + ' no' + key, + url: 'Disable ' + properties.docs[key], + } + ]; + } + return [ + { + caption: key, + content: command + ' ' + key, + url: 'Set ' + properties.docs[key], + } + ]; + }).flat(); + return Promise.resolve([ + { + name: 'Properties', + items, + } + ]); +}; + const complete = (line, settings) => { let trimmed = line.trimStart(); let words = trimmed.split(/ +/); @@ -121,6 +156,8 @@ const complete = (line, settings) => { case 'bdelete': case 'bdeletes': return getBufferCompletions(name, keywords, true); + case 'set': + return getSetCompletions(name, keywords); } return Promise.resolve([]); }; diff --git a/src/shared/settings/properties.js b/src/shared/settings/properties.js index 4bda8d6..b392cbb 100644 --- a/src/shared/settings/properties.js +++ b/src/shared/settings/properties.js @@ -15,4 +15,10 @@ const defaults = { adjacenttab: true, }; -export { types, defaults }; +const docs = { + hintchars: 'Hint characters on follow mode', + smoothscroll: 'smooth scroll', + adjacenttab: 'open adjacent tabs', +}; + +export { types, defaults, docs }; -- cgit v1.2.3 From f555e1348c8e383983487a79f797fe06540862f4 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 13 Jul 2018 21:49:34 +0900 Subject: Fix command and property completions --- src/background/shared/completions/index.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/background/shared/completions') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index d630f33..4fd37fd 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -113,6 +113,9 @@ const getSetCompletions = (command, keywords) => { } ]; }).flat(); + if (items.length === 0) { + return Promise.resolve([]); + } return Promise.resolve([ { name: 'Properties', @@ -126,6 +129,10 @@ const complete = (line, settings) => { let words = trimmed.split(/ +/); let name = words[0]; if (words.length === 1) { + let items = completeCommands(name); + if (items.length === 0) { + return Promise.resolve([]); + } return Promise.resolve([ { name: 'Console Command', -- cgit v1.2.3 From ccc6a31ddeab78660305d9088e8260156b251779 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 13 Jul 2018 22:09:04 +0900 Subject: fix --- src/background/shared/completions/index.js | 2 +- src/console/reducers/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/background/shared/completions') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index 4fd37fd..d0d00ef 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -130,7 +130,7 @@ const complete = (line, settings) => { let name = words[0]; if (words.length === 1) { let items = completeCommands(name); - if (items.length === 0) { + if (items.length === 0) { return Promise.resolve([]); } return Promise.resolve([ diff --git a/src/console/reducers/index.js b/src/console/reducers/index.js index 043689c..7dcad17 100644 --- a/src/console/reducers/index.js +++ b/src/console/reducers/index.js @@ -13,7 +13,7 @@ const defaultState = { const nextSelection = (state) => { if (state.completions.length === 0) { return [-1, -1]; - }; + } if (state.groupSelection < 0) { return [0, 0]; } -- cgit v1.2.3 From 803e6ea7af60107182356b5fda8e3c2ddfacaefa Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 13 Jul 2018 22:14:19 +0900 Subject: Replace flat with reduce-concat --- src/background/shared/completions/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/background/shared/completions') diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js index d0d00ef..9ca13f7 100644 --- a/src/background/shared/completions/index.js +++ b/src/background/shared/completions/index.js @@ -112,7 +112,8 @@ const getSetCompletions = (command, keywords) => { url: 'Set ' + properties.docs[key], } ]; - }).flat(); + }); + items = items.reduce((acc, val) => acc.concat(val), []); if (items.length === 0) { return Promise.resolve([]); } -- cgit v1.2.3