aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/background/controllers/CommandController.ts38
-rw-r--r--src/background/domains/CommandDocs.ts12
-rw-r--r--src/background/domains/CompletionGroup.ts6
-rw-r--r--src/background/domains/CompletionItem.ts6
-rw-r--r--src/background/infrastructures/ContentMessageListener.ts8
-rw-r--r--src/background/repositories/CompletionsRepository.ts16
-rw-r--r--src/background/usecases/CompletionsUseCase.ts205
-rw-r--r--src/console/actions/console.ts14
-rw-r--r--src/console/components/Console.tsx8
-rw-r--r--src/shared/messages.ts8
10 files changed, 2 insertions, 319 deletions
diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts
index 7297ef8..16aa6e8 100644
--- a/src/background/controllers/CommandController.ts
+++ b/src/background/controllers/CommandController.ts
@@ -1,7 +1,5 @@
import { injectable } from 'tsyringe';
-import CompletionsUseCase from '../usecases/CompletionsUseCase';
import CommandUseCase from '../usecases/CommandUseCase';
-import CompletionGroup from '../domains/CompletionGroup';
const trimStart = (str: string): string => {
// NOTE String.trimStart is available on Firefox 61
@@ -11,46 +9,10 @@ const trimStart = (str: string): string => {
@injectable()
export default class CommandController {
constructor(
- private completionsUseCase: CompletionsUseCase,
private commandIndicator: CommandUseCase,
) {
}
- getCompletions(line: string): Promise<CompletionGroup[]> {
- const trimmed = trimStart(line);
- const words = trimmed.split(/ +/);
- const name = words[0];
- if (words.length === 1) {
- return this.completionsUseCase.queryConsoleCommand(name);
- }
- const keywords = trimStart(trimmed.slice(name.length));
- switch (words[0]) {
- case 'o':
- case 'open':
- case 't':
- case 'tabopen':
- case 'w':
- case 'winopen':
- return this.completionsUseCase.queryOpen(name, keywords);
- case 'b':
- case 'buffer':
- return this.completionsUseCase.queryBuffer(name, keywords);
- case 'bd':
- case 'bdel':
- case 'bdelete':
- case 'bdeletes':
- return this.completionsUseCase.queryBdelete(name, keywords);
- case 'bd!':
- case 'bdel!':
- case 'bdelete!':
- case 'bdeletes!':
- return this.completionsUseCase.queryBdeleteForce(name, keywords);
- case 'set':
- return this.completionsUseCase.querySet(name, keywords);
- }
- return Promise.resolve([]);
- }
-
// eslint-disable-next-line complexity
exec(line: string): Promise<any> {
const trimmed = trimStart(line);
diff --git a/src/background/domains/CommandDocs.ts b/src/background/domains/CommandDocs.ts
deleted file mode 100644
index e926851..0000000
--- a/src/background/domains/CommandDocs.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-export default {
- set: 'Set a value of the property',
- open: 'Open a URL or search by keywords in current tab',
- tabopen: 'Open a URL or search by keywords in new tab',
- winopen: 'Open a URL or search by keywords in new window',
- buffer: 'Select tabs by matched keywords',
- bdelete: 'Close a certain tab matched by keywords',
- bdeletes: 'Close all tabs matched by keywords',
- quit: 'Close the current tab',
- quitall: 'Close all tabs',
- help: 'Open Vim Vixen help in new tab',
-} as {[key: string]: string};
diff --git a/src/background/domains/CompletionGroup.ts b/src/background/domains/CompletionGroup.ts
deleted file mode 100644
index 8e89bf0..0000000
--- a/src/background/domains/CompletionGroup.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import CompletionItem from './CompletionItem';
-
-export default interface CompletionGroup {
- name: string;
- items: CompletionItem[];
-}
diff --git a/src/background/domains/CompletionItem.ts b/src/background/domains/CompletionItem.ts
deleted file mode 100644
index 96f6ee6..0000000
--- a/src/background/domains/CompletionItem.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export default interface CompletionItem {
- readonly caption?: string;
- readonly content?: string;
- readonly url?: string;
- readonly icon?: string;
-}
diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts
index 92481da..2fbb9cf 100644
--- a/src/background/infrastructures/ContentMessageListener.ts
+++ b/src/background/infrastructures/ContentMessageListener.ts
@@ -1,7 +1,6 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages';
import * as operations from '../../shared/operations';
-import CompletionGroup from '../domains/CompletionGroup';
import CommandController from '../controllers/CommandController';
import SettingController from '../controllers/SettingController';
import FindController from '../controllers/FindController';
@@ -63,8 +62,6 @@ export default class ContentMessageListener {
message: messages.Message, senderTab: browser.tabs.Tab,
): Promise<any> | any {
switch (message.type) {
- case messages.CONSOLE_QUERY_COMPLETIONS:
- return this.onConsoleQueryCompletions(message.text);
case messages.CONSOLE_GET_COMPLETION_TYPES:
return this.completionController.getCompletionTypes();
case messages.CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE:
@@ -107,11 +104,6 @@ export default class ContentMessageListener {
throw new Error('unsupported message: ' + message.type);
}
- async onConsoleQueryCompletions(line: string): Promise<CompletionGroup[]> {
- const completions = await this.commandController.getCompletions(line);
- return Promise.resolve(completions);
- }
-
onConsoleEnterCommand(text: string): Promise<any> {
return this.commandController.exec(text);
}
diff --git a/src/background/repositories/CompletionsRepository.ts b/src/background/repositories/CompletionsRepository.ts
deleted file mode 100644
index 7d0434c..0000000
--- a/src/background/repositories/CompletionsRepository.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { injectable } from 'tsyringe';
-
-type Tab = browser.tabs.Tab;
-
-@injectable()
-export default class CompletionsRepository {
- async queryTabs(keywords: string, excludePinned: boolean): Promise<Tab[]> {
- const tabs = await browser.tabs.query({ currentWindow: true });
- return tabs.filter((t) => {
- return t.url && t.url.toLowerCase().includes(keywords.toLowerCase()) ||
- t.title && t.title.toLowerCase().includes(keywords.toLowerCase());
- }).filter((t) => {
- return !(excludePinned && t.pinned);
- });
- }
-}
diff --git a/src/background/usecases/CompletionsUseCase.ts b/src/background/usecases/CompletionsUseCase.ts
deleted file mode 100644
index 439c81a..0000000
--- a/src/background/usecases/CompletionsUseCase.ts
+++ /dev/null
@@ -1,205 +0,0 @@
-import { injectable, inject } from 'tsyringe';
-import CompletionGroup from '../domains/CompletionGroup';
-import CommandDocs from '../domains/CommandDocs';
-import CompletionsRepository from '../repositories/CompletionsRepository';
-import CachedSettingRepository from '../repositories/CachedSettingRepository';
-import TabPresenter from '../presenters/TabPresenter';
-import Properties from '../../shared/settings/Properties';
-import OpenCompletionUseCase from "../completion/OpenCompletionUseCase";
-
-type Tab = browser.tabs.Tab;
-
-@injectable()
-export default class CompletionsUseCase {
- constructor(
- @inject('TabPresenter') private tabPresenter: TabPresenter,
- private completionsRepository: CompletionsRepository,
- @inject("CachedSettingRepository") private cachedSettingRepository: CachedSettingRepository,
- private completionUseCase: OpenCompletionUseCase
- ) {
- }
-
- queryConsoleCommand(prefix: string): Promise<CompletionGroup[]> {
- const keys = Object.keys(CommandDocs);
- const items = keys
- .filter(name => name.startsWith(prefix))
- .map(name => ({
- caption: name,
- content: name,
- url: CommandDocs[name],
- }));
-
- if (items.length === 0) {
- return Promise.resolve([]);
- }
- return Promise.resolve([{ name: 'Console Command', items }]);
- }
-
- async queryOpen(name: string, keywords: string): Promise<CompletionGroup[]> {
- // TODO This logic contains view entities. They should be defined on
- // content script
-
- const settings = await this.cachedSettingRepository.get();
- const groups: CompletionGroup[] = [];
-
- const complete = settings.properties.complete;
- for (const c of complete) {
- if (c === 's') {
- // eslint-disable-next-line no-await-in-loop
- const engines = await this.querySearchEngineItems(name, keywords);
- if (engines.length > 0) {
- groups.push({ name: 'Search Engines', items: engines });
- }
- // browser.history not supported on Android
- } else if (c === 'h' && typeof browser.history === 'object') {
- // eslint-disable-next-line no-await-in-loop
- const histories = await this.queryHistoryItems(name, keywords);
- if (histories.length > 0) {
- groups.push({ name: 'History', items: histories });
- }
- // browser.bookmarks not supported on Android
- } else if (c === 'b' && typeof browser.bookmarks === 'object') {
- // eslint-disable-next-line no-await-in-loop
- const bookmarks = await this.queryBookmarkItems(name, keywords);
- if (bookmarks.length > 0) {
- groups.push({ name: 'Bookmarks', items: bookmarks });
- }
- }
- }
- return groups;
- }
-
- // eslint-disable-next-line max-statements
- async queryBuffer(
- name: string,
- keywords: string,
- ): Promise<CompletionGroup[]> {
- const lastId = await this.tabPresenter.getLastSelectedId();
- const trimmed = keywords.trim();
- let tabs: Tab[] = [];
- if (trimmed.length > 0 && !isNaN(Number(trimmed))) {
- const all = await this.tabPresenter.getAll();
- const index = parseInt(trimmed, 10) - 1;
- if (index >= 0 && index < all.length) {
- tabs = [all[index]];
- }
- } else if (trimmed === '%') {
- const all = await this.tabPresenter.getAll();
- const tab = all.find(t => t.active) as Tab;
- tabs = [tab];
- } else if (trimmed === '#') {
- if (typeof lastId !== 'undefined' && lastId !== null) {
- const all = await this.tabPresenter.getAll();
- const tab = all.find(t => t.id === lastId) as Tab;
- tabs = [tab];
- }
- } else {
- tabs = await this.completionsRepository.queryTabs(keywords, false);
- }
- const flag = (tab: Tab) => {
- if (tab.active) {
- return '%';
- } else if (tab.id === lastId) {
- return '#';
- }
- return ' ';
- };
- const items = tabs.map(tab => ({
- caption: tab.index + 1 + ': ' + flag(tab) + ' ' + tab.title,
- content: name + ' ' + tab.title,
- url: tab.url,
- icon: tab.favIconUrl,
- }));
- if (items.length === 0) {
- return Promise.resolve([]);
- }
- return [{ name: 'Buffers', items }];
- }
-
- queryBdelete(name: string, keywords: string): Promise<CompletionGroup[]> {
- return this.queryTabs(name, true, keywords);
- }
-
- queryBdeleteForce(
- name: string, keywords: string,
- ): Promise<CompletionGroup[]> {
- return this.queryTabs(name, false, keywords);
- }
-
- querySet(name: string, keywords: string): Promise<CompletionGroup[]> {
- const items = Properties.defs().map((def) => {
- if (def.type === 'boolean') {
- return [
- {
- caption: def.name,
- content: name + ' ' + def.name,
- url: 'Enable ' + def.description,
- }, {
- caption: 'no' + def.name,
- content: name + ' no' + def.name,
- url: 'Disable ' + def.description
- }
- ];
- }
- return [
- {
- caption: def.name,
- content: name + ' ' + def.name,
- url: 'Set ' + def.description,
- }
- ];
- });
- let flatten = items.reduce((acc, val) => acc.concat(val), []);
- flatten = flatten.filter((item) => {
- return item.caption.startsWith(keywords);
- });
- if (flatten.length === 0) {
- return Promise.resolve([]);
- }
- return Promise.resolve(
- [{ name: 'Properties', items: flatten }],
- );
- }
-
- async queryTabs(
- name: string, excludePinned: boolean, args: string,
- ): Promise<CompletionGroup[]> {
- const tabs = await this.completionsRepository.queryTabs(args, excludePinned);
- const items = tabs.map(tab => ({
- caption: tab.title,
- content: name + ' ' + tab.title,
- url: tab.url,
- icon: tab.favIconUrl
- }));
- if (items.length === 0) {
- return Promise.resolve([]);
- }
- return [{ name: 'Buffers', items }];
- }
-
- async querySearchEngineItems(name: string, query: string) {
- const engines = await this.completionUseCase.requestSearchEngines(query);
- return engines.map(item => ({
- caption: item,
- content: name + ' ' + item,
- }));
- }
-
- async queryHistoryItems(name: string, query: string) {
- const items = await this.completionUseCase.requestHistory(query);
- return items.map(item => ({
- caption: item.title,
- content: name + ' ' + item.url,
- url: item.url
- }));
- }
-
- async queryBookmarkItems(name: string, query: string) {
- const items = await this.completionUseCase.requestHistory(query);
- return items.map(item => ({
- caption: item.title,
- content: name + ' ' + item.url,
- url: item.url
- }));
- }
-}
diff --git a/src/console/actions/console.ts b/src/console/actions/console.ts
index b17754d..e44c974 100644
--- a/src/console/actions/console.ts
+++ b/src/console/actions/console.ts
@@ -232,18 +232,6 @@ const getPropertyCompletions = async(
}
};
-const getCompletions = async(text: string): Promise<actions.SetCompletionsAction> => {
- const completions = await browser.runtime.sendMessage({
- type: messages.CONSOLE_QUERY_COMPLETIONS,
- text,
- });
- return {
- type: actions.CONSOLE_SET_COMPLETIONS,
- completions,
- completionSource: text,
- };
-};
-
const completionNext = (): actions.CompletionNextAction => {
return {
type: actions.CONSOLE_COMPLETION_NEXT,
@@ -258,6 +246,6 @@ const completionPrev = (): actions.CompletionPrevAction => {
export {
hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, enterCommand, enterFind,
- getCompletions, getCommandCompletions, getOpenCompletions, getTabCompletions, getPropertyCompletions,
+ getCommandCompletions, getOpenCompletions, getTabCompletions, getPropertyCompletions,
completionNext, completionPrev,
};
diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx
index 77f1b09..3fe5cee 100644
--- a/src/console/components/Console.tsx
+++ b/src/console/components/Console.tsx
@@ -175,22 +175,16 @@ class Console extends React.Component<Props> {
this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, false));
break;
case Command.BufferDelete:
- this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, true));
- break;
- case Command.BufferDeleteForce:
- this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, false));
- break;
case Command.BuffersDelete:
this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, true));
break;
+ case Command.BufferDeleteForce:
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 577c34c..edb7935 100644
--- a/src/shared/messages.ts
+++ b/src/shared/messages.ts
@@ -7,7 +7,6 @@ export const BACKGROUND_OPERATION = 'background.operation';
export const CONSOLE_UNFOCUS = 'console.unfocus';
export const CONSOLE_ENTER_COMMAND = 'console.enter.command';
export const CONSOLE_ENTER_FIND = 'console.enter.find';
-export const CONSOLE_QUERY_COMPLETIONS = 'console.query.completions'; // DEPRECATED
export const CONSOLE_SHOW_COMMAND = 'console.show.command';
export const CONSOLE_SHOW_ERROR = 'console.show.error';
export const CONSOLE_SHOW_INFO = 'console.show.info';
@@ -75,11 +74,6 @@ export interface ConsoleEnterFindMessage {
text?: string;
}
-export interface ConsoleQueryCompletionsMessage {
- type: typeof CONSOLE_QUERY_COMPLETIONS;
- text: string;
-}
-
export interface ConsoleShowCommandMessage {
type: typeof CONSOLE_SHOW_COMMAND;
command: string;
@@ -297,7 +291,6 @@ export type Message =
ConsoleUnfocusMessage |
ConsoleEnterCommandMessage |
ConsoleEnterFindMessage |
- ConsoleQueryCompletionsMessage |
ConsoleShowCommandMessage |
ConsoleShowErrorMessage |
ConsoleShowInfoMessage |
@@ -342,7 +335,6 @@ export const valueOf = (o: any): Message => {
case CONSOLE_UNFOCUS:
case CONSOLE_ENTER_COMMAND:
case CONSOLE_ENTER_FIND:
- case CONSOLE_QUERY_COMPLETIONS:
case CONSOLE_SHOW_COMMAND:
case CONSOLE_SHOW_ERROR:
case CONSOLE_SHOW_INFO: