aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-03-29 21:47:09 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2020-03-29 21:47:09 +0900
commitc3be3dde555d1f51f696f4bfbe181e7bad6d3563 (patch)
treec42d2b9115f3aca5fd90d7a72baa6990ae388c21 /src
parent0340c82bc82738a63c8a374930cf39cbed5c7c8c (diff)
Complete properties on set command
Diffstat (limited to 'src')
-rw-r--r--src/background/completion/PropertyCompletionUseCase.ts16
-rw-r--r--src/background/controllers/CompletionController.ts7
-rw-r--r--src/background/infrastructures/ContentMessageListener.ts2
-rw-r--r--src/console/actions/console.ts43
-rw-r--r--src/console/clients/CompletionClient.ts14
-rw-r--r--src/console/components/Console.tsx3
-rw-r--r--src/shared/messages.ts13
7 files changed, 94 insertions, 4 deletions
diff --git a/src/background/completion/PropertyCompletionUseCase.ts b/src/background/completion/PropertyCompletionUseCase.ts
new file mode 100644
index 0000000..049cfb8
--- /dev/null
+++ b/src/background/completion/PropertyCompletionUseCase.ts
@@ -0,0 +1,16 @@
+import { injectable } from "tsyringe";
+import Properties from "../../shared/settings/Properties";
+
+type Property = {
+ name: string;
+ type: 'string' | 'boolean' | 'number';
+}
+@injectable()
+export default class PropertyCompletionUseCase {
+ async getProperties(): Promise<Property[]> {
+ return Properties.defs().map(def => ({
+ name: def.name,
+ type: def.type,
+ }));
+ }
+} \ No newline at end of file
diff --git a/src/background/controllers/CompletionController.ts b/src/background/controllers/CompletionController.ts
index a268d15..fb6137c 100644
--- a/src/background/controllers/CompletionController.ts
+++ b/src/background/controllers/CompletionController.ts
@@ -1,5 +1,6 @@
import {
ConsoleGetCompletionTypesResponse,
+ ConsoleGetPropertiesResponse,
ConsoleRequestBookmarksResponse,
ConsoleRequestHistoryResponse,
ConsoleRequestSearchEnginesResponse,
@@ -8,12 +9,14 @@ import {
import { injectable } from "tsyringe";
import OpenCompletionUseCase from "../completion/OpenCompletionUseCase";
import TabCompletionUseCase from "../completion/TabCompletionUseCase";
+import PropertyCompletionUseCase from "../completion/PropertyCompletionUseCase";
@injectable()
export default class CompletionController {
constructor(
private completionUseCase: OpenCompletionUseCase,
private tabCompletionUseCase: TabCompletionUseCase,
+ private propertyCompletionUseCase: PropertyCompletionUseCase,
) {
}
@@ -37,4 +40,8 @@ export default class CompletionController {
async queryTabs(query: string, excludePinned: boolean): Promise<ConsoleRequesttabsResponse> {
return this.tabCompletionUseCase.queryTabs(query, excludePinned);
}
+
+ async getProperties(): Promise<ConsoleGetPropertiesResponse> {
+ return this.propertyCompletionUseCase.getProperties();
+ }
} \ No newline at end of file
diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts
index 13aa763..92481da 100644
--- a/src/background/infrastructures/ContentMessageListener.ts
+++ b/src/background/infrastructures/ContentMessageListener.ts
@@ -75,6 +75,8 @@ export default class ContentMessageListener {
return this.completionController.requestHistory(message.query);
case messages.CONSOLE_REQUEST_TABS:
return this.completionController.queryTabs(message.query, message.excludePinned);
+ case messages.CONSOLE_GET_PROPERTIES:
+ return this.completionController.getProperties();
case messages.CONSOLE_ENTER_COMMAND:
return this.onConsoleEnterCommand(message.text);
case messages.SETTINGS_QUERY:
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));
}
diff --git a/src/shared/messages.ts b/src/shared/messages.ts
index 3f6b7bf..577c34c 100644
--- a/src/shared/messages.ts
+++ b/src/shared/messages.ts
@@ -13,11 +13,12 @@ export const CONSOLE_SHOW_ERROR = 'console.show.error';
export const CONSOLE_SHOW_INFO = 'console.show.info';
export const CONSOLE_SHOW_FIND = 'console.show.find';
export const CONSOLE_HIDE = 'console.hide';
-export const CONSOLE_GET_COMPLETION_TYPES = 'console.get.completion.types'
+export const CONSOLE_GET_COMPLETION_TYPES = 'console.get.completion.types';
export const CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE = 'console.qresut.searchEngines';
export const CONSOLE_REQUEST_BOOKMARKS = 'console.request.bookmarks';
export const CONSOLE_REQUEST_HISTORY = 'console.request.history';
export const CONSOLE_REQUEST_TABS = 'console.request.tabs';
+export const CONSOLE_GET_PROPERTIES = 'console.get.properties';
export const FOLLOW_START = 'follow.start';
export const FOLLOW_REQUEST_COUNT_TARGETS = 'follow.request.count.targets';
@@ -127,6 +128,10 @@ export interface ConsoleRequestTabsMessage {
excludePinned: boolean;
}
+export interface ConsoleGetPropertiesMessage {
+ type: typeof CONSOLE_GET_PROPERTIES;
+}
+
export type ConsoleRequesttabsResponse = {
index: number
flag: TabFlag
@@ -151,6 +156,11 @@ export type ConsoleRequestHistoryResponse = {
url: string;
}[]
+export type ConsoleGetPropertiesResponse = {
+ name: string
+ type: 'string' | 'boolean' | 'number'
+}[]
+
export interface FollowStartMessage {
type: typeof FOLLOW_START;
newTab: boolean;
@@ -296,6 +306,7 @@ export type Message =
ConsoleRequestBookmarksMessage |
ConsoleRequestHistoryMessage |
ConsoleRequestTabsMessage |
+ ConsoleGetPropertiesMessage |
ConsoleGetCompletionTypesMessage |
ConsoleRequestSearchEnginesMessage |
FollowStartMessage |