From c3be3dde555d1f51f696f4bfbe181e7bad6d3563 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 29 Mar 2020 21:47:09 +0900 Subject: Complete properties on set command --- src/console/actions/console.ts | 43 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/console/actions/console.ts') diff --git a/src/console/actions/console.ts b/src/console/actions/console.ts index 89d9c3c..b17754d 100644 --- a/src/console/actions/console.ts +++ b/src/console/actions/console.ts @@ -22,6 +22,12 @@ const commandDocs = { [Command.Help]: 'Open Vim Vixen help in new tab', }; +const propertyDocs: {[key: string]: string} = { + 'hintchars': 'hint characters on follow mode', + 'smoothscroll': 'smooth scroll', + 'complete': 'which are completed at the open page', +}; + const hide = (): actions.ConsoleAction => { return { type: actions.CONSOLE_HIDE, @@ -191,7 +197,40 @@ const getTabCompletions = async ( } }; - +const getPropertyCompletions = async( + original: string, command: Command, query: string, +): Promise => { + const properties = await completionClient.getProperties(); + const items = properties + .map(item => { + const desc = propertyDocs[item.name] || ''; + if (item.type === 'boolean') { + return [{ + caption: item.name, + content: command + ' ' + item.name, + url: 'Enable ' + desc, + }, { + caption: 'no' + item.name, + content: command + ' no' + item.name, + url: 'Disable ' + desc, + }]; + } else { + return [{ + caption: item.name, + content: name + ' ' + item.name, + url: 'Set ' + desc, + }]; + } + }) + .reduce((acc, val) => acc.concat(val), []) + .filter(item => item.caption.startsWith(query)); + const completions: Completions = [{ name: 'Properties', items }]; + return { + type: actions.CONSOLE_SET_COMPLETIONS, + completions, + completionSource: original, + } +}; const getCompletions = async(text: string): Promise => { const completions = await browser.runtime.sendMessage({ @@ -219,6 +258,6 @@ const completionPrev = (): actions.CompletionPrevAction => { export { hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, enterCommand, enterFind, - getCompletions, getCommandCompletions, getOpenCompletions, getTabCompletions, + getCompletions, getCommandCompletions, getOpenCompletions, getTabCompletions, getPropertyCompletions, completionNext, completionPrev, }; -- cgit v1.2.3