diff options
Diffstat (limited to 'src/console')
-rw-r--r-- | src/console/actions/console.ts | 43 | ||||
-rw-r--r-- | src/console/clients/CompletionClient.ts | 14 | ||||
-rw-r--r-- | src/console/components/Console.tsx | 3 |
3 files changed, 57 insertions, 3 deletions
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<actions.SetCompletionsAction> => { + 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<actions.SetCompletionsAction> => { 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, }; diff --git a/src/console/clients/CompletionClient.ts b/src/console/clients/CompletionClient.ts index 19b4d99..56dc665 100644 --- a/src/console/clients/CompletionClient.ts +++ b/src/console/clients/CompletionClient.ts @@ -1,6 +1,6 @@ import * as messages from "../../shared/messages"; import { - ConsoleGetCompletionTypesResponse, + ConsoleGetCompletionTypesResponse, ConsoleGetPropertiesResponse, ConsoleRequestBookmarksResponse, ConsoleRequestHistoryResponse, ConsoleRequestSearchEnginesResponse, ConsoleRequesttabsResponse } from "../../shared/messages"; @@ -29,6 +29,11 @@ export type TabItem = { faviconUrl?: string } +export type Property = { + name: string + type: 'string' | 'boolean' | 'number'; +} + export default class CompletionClient { async getCompletionTypes(): Promise<CompletionType[]> { const resp = await browser.runtime.sendMessage({ @@ -69,4 +74,11 @@ export default class CompletionClient { }) as ConsoleRequesttabsResponse; return resp; } + + async getProperties(): Promise<Property[]> { + const resp = await browser.runtime.sendMessage({ + type: messages.CONSOLE_GET_PROPERTIES, + }) as ConsoleGetPropertiesResponse; + return resp; + } } diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx index c1709cd..77f1b09 100644 --- a/src/console/components/Console.tsx +++ b/src/console/components/Console.tsx @@ -186,6 +186,9 @@ class Console extends React.Component<Props> { case Command.BuffersDeleteForce: this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, false)); break; + case Command.Set: + this.props.dispatch(consoleActions.getPropertyCompletions(text, cmd.command, cmd.args)); + break; default: this.props.dispatch(consoleActions.getCompletions(text)); } |