diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/background/controllers/FindController.ts | 15 | ||||
-rw-r--r-- | src/background/infrastructures/ContentMessageListener.ts | 14 | ||||
-rw-r--r-- | src/background/repositories/FindRepository.ts | 22 | ||||
-rw-r--r-- | src/background/usecases/FindUseCase.ts | 15 | ||||
-rw-r--r-- | src/content/Application.ts | 8 | ||||
-rw-r--r-- | src/content/client/FindClient.ts | 23 | ||||
-rw-r--r-- | src/content/client/FindMasterClient.ts | 27 | ||||
-rw-r--r-- | src/content/controllers/FindController.ts | 20 | ||||
-rw-r--r-- | src/content/di.ts | 8 | ||||
-rw-r--r-- | src/content/operators/impls/FindNextOperator.ts | 15 | ||||
-rw-r--r-- | src/content/operators/impls/FindOperatorFactoryChain.ts | 25 | ||||
-rw-r--r-- | src/content/operators/impls/FindPrevOperator.ts | 15 | ||||
-rw-r--r-- | src/content/operators/impls/OperatorFactoryImpl.ts | 3 | ||||
-rw-r--r-- | src/content/presenters/FindPresenter.ts | 29 | ||||
-rw-r--r-- | src/content/repositories/FindRepository.ts | 17 | ||||
-rw-r--r-- | src/content/usecases/FindUseCase.ts | 67 | ||||
-rw-r--r-- | src/shared/messages.ts | 31 |
17 files changed, 0 insertions, 354 deletions
diff --git a/src/background/controllers/FindController.ts b/src/background/controllers/FindController.ts deleted file mode 100644 index f3ea93f..0000000 --- a/src/background/controllers/FindController.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { injectable } from "tsyringe"; -import FindUseCase from "../usecases/FindUseCase"; - -@injectable() -export default class FindController { - constructor(private findUseCase: FindUseCase) {} - - getKeyword(): Promise<string> { - return this.findUseCase.getKeyword(); - } - - setKeyword(keyword: string): Promise<void> { - return this.findUseCase.setKeyword(keyword); - } -} diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts index 6023047..4a6a3b8 100644 --- a/src/background/infrastructures/ContentMessageListener.ts +++ b/src/background/infrastructures/ContentMessageListener.ts @@ -3,7 +3,6 @@ import * as messages from "../../shared/messages"; import * as operations from "../../shared/operations"; import CommandController from "../controllers/CommandController"; import SettingController from "../controllers/SettingController"; -import FindController from "../controllers/FindController"; import AddonEnabledController from "../controllers/AddonEnabledController"; import LinkController from "../controllers/LinkController"; import OperationController from "../controllers/OperationController"; @@ -19,7 +18,6 @@ export default class ContentMessageListener { private readonly settingController: SettingController, private readonly commandController: CommandController, private readonly completionController: CompletionController, - private readonly findController: FindController, private readonly addonEnabledController: AddonEnabledController, private readonly linkController: LinkController, private readonly operationController: OperationController, @@ -88,10 +86,6 @@ export default class ContentMessageListener { ); case messages.SETTINGS_QUERY: return this.onSettingsQuery(); - case messages.FIND_GET_KEYWORD: - return this.onFindGetKeyword(); - case messages.FIND_SET_KEYWORD: - return this.onFindSetKeyword(message.keyword); case messages.ADDON_ENABLED_RESPONSE: return this.onAddonEnabledResponse(message.enabled); case messages.OPEN_URL: @@ -132,14 +126,6 @@ export default class ContentMessageListener { return (await this.settingController.getSetting()).toJSON(); } - onFindGetKeyword(): Promise<string> { - return this.findController.getKeyword(); - } - - onFindSetKeyword(keyword: string): Promise<void> { - return this.findController.setKeyword(keyword); - } - onAddonEnabledResponse(enabled: boolean): Promise<void> { return this.addonEnabledController.indicate(enabled); } diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts deleted file mode 100644 index 813e065..0000000 --- a/src/background/repositories/FindRepository.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { injectable } from "tsyringe"; -import MemoryStorage from "../infrastructures/MemoryStorage"; - -const FIND_KEYWORD_KEY = "find-keyword"; - -@injectable() -export default class FindRepository { - private cache: MemoryStorage; - - constructor() { - this.cache = new MemoryStorage(); - } - - getKeyword(): Promise<string> { - return Promise.resolve(this.cache.get(FIND_KEYWORD_KEY)); - } - - setKeyword(keyword: string): Promise<void> { - this.cache.set(FIND_KEYWORD_KEY, keyword); - return Promise.resolve(); - } -} diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts deleted file mode 100644 index cc111f2..0000000 --- a/src/background/usecases/FindUseCase.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { injectable } from "tsyringe"; -import FindRepository from "../repositories/FindRepository"; - -@injectable() -export default class FindUseCase { - constructor(private readonly findRepository: FindRepository) {} - - getKeyword(): Promise<string> { - return this.findRepository.getKeyword(); - } - - setKeyword(keyword: string): Promise<void> { - return this.findRepository.setKeyword(keyword); - } -} diff --git a/src/content/Application.ts b/src/content/Application.ts index b09edfa..4c89fa0 100644 --- a/src/content/Application.ts +++ b/src/content/Application.ts @@ -1,6 +1,5 @@ import { injectable } from "tsyringe"; import MessageListener from "./MessageListener"; -import FindController from "./controllers/FindController"; import MarkController from "./controllers/MarkController"; import FollowMasterController from "./controllers/FollowMasterController"; import FollowSlaveController from "./controllers/FollowSlaveController"; @@ -22,7 +21,6 @@ export default class Application { // eslint-disable-next-line max-params constructor( private messageListener: MessageListener, - private findController: FindController, private markController: MarkController, private followMasterController: FollowMasterController, private followSlaveController: FollowSlaveController, @@ -47,12 +45,6 @@ export default class Application { private routeMasterComponents() { this.messageListener.onWebMessage((msg: Message, sender: Window) => { switch (msg.type) { - case messages.CONSOLE_ENTER_FIND: - return this.findController.start(msg); - case messages.FIND_NEXT: - return this.findController.next(msg); - case messages.FIND_PREV: - return this.findController.prev(msg); case messages.CONSOLE_UNFOCUS: return this.consoleFrameController.unfocus(msg); case messages.FOLLOW_START: diff --git a/src/content/client/FindClient.ts b/src/content/client/FindClient.ts deleted file mode 100644 index 7da5069..0000000 --- a/src/content/client/FindClient.ts +++ /dev/null @@ -1,23 +0,0 @@ -import * as messages from "../../shared/messages"; - -export default interface FindClient { - getGlobalLastKeyword(): Promise<string | null>; - - setGlobalLastKeyword(keyword: string): Promise<void>; -} - -export class FindClientImpl implements FindClient { - async getGlobalLastKeyword(): Promise<string | null> { - const keyword = await browser.runtime.sendMessage({ - type: messages.FIND_GET_KEYWORD, - }); - return keyword as string; - } - - async setGlobalLastKeyword(keyword: string): Promise<void> { - await browser.runtime.sendMessage({ - type: messages.FIND_SET_KEYWORD, - keyword: keyword, - }); - } -} diff --git a/src/content/client/FindMasterClient.ts b/src/content/client/FindMasterClient.ts deleted file mode 100644 index 9c3f812..0000000 --- a/src/content/client/FindMasterClient.ts +++ /dev/null @@ -1,27 +0,0 @@ -import * as messages from "../../shared/messages"; - -export default interface FindMasterClient { - findNext(): void; - - findPrev(): void; -} - -export class FindMasterClientImpl implements FindMasterClient { - findNext(): void { - window.top.postMessage( - JSON.stringify({ - type: messages.FIND_NEXT, - }), - "*" - ); - } - - findPrev(): void { - window.top.postMessage( - JSON.stringify({ - type: messages.FIND_PREV, - }), - "*" - ); - } -} diff --git a/src/content/controllers/FindController.ts b/src/content/controllers/FindController.ts deleted file mode 100644 index 3087d5d..0000000 --- a/src/content/controllers/FindController.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { injectable } from "tsyringe"; -import * as messages from "../../shared/messages"; -import FindUseCase from "../usecases/FindUseCase"; - -@injectable() -export default class FindController { - constructor(private findUseCase: FindUseCase) {} - - async start(m: messages.ConsoleEnterFindMessage): Promise<void> { - await this.findUseCase.startFind(m.text); - } - - async next(_: messages.FindNextMessage): Promise<void> { - await this.findUseCase.findNext(); - } - - async prev(_: messages.FindPrevMessage): Promise<void> { - await this.findUseCase.findPrev(); - } -} diff --git a/src/content/di.ts b/src/content/di.ts index e74d7ac..7a7fb08 100644 --- a/src/content/di.ts +++ b/src/content/di.ts @@ -6,10 +6,6 @@ import { AddressRepositoryImpl } from "./repositories/AddressRepository"; import { ClipboardRepositoryImpl } from "./repositories/ClipboardRepository"; import { ConsoleClientImpl } from "./client/ConsoleClient"; import { ConsoleFramePresenterImpl } from "./presenters/ConsoleFramePresenter"; -import { FindClientImpl } from "./client/FindClient"; -import { FindMasterClientImpl } from "./client/FindMasterClient"; -import { FindPresenterImpl } from "./presenters/FindPresenter"; -import { FindRepositoryImpl } from "./repositories/FindRepository"; import { FocusPresenterImpl } from "./presenters/FocusPresenter"; import { FollowKeyRepositoryImpl } from "./repositories/FollowKeyRepository"; import { FollowMasterClientImpl } from "./client/FollowMasterClient"; @@ -49,10 +45,6 @@ container.register("ConsoleClient", { useClass: ConsoleClientImpl }); container.register("ConsoleFramePresenter", { useClass: ConsoleFramePresenterImpl, }); -container.register("FindClient", { useClass: FindClientImpl }); -container.register("FindMasterClient", { useClass: FindMasterClientImpl }); -container.register("FindPresenter", { useClass: FindPresenterImpl }); -container.register("FindRepository", { useClass: FindRepositoryImpl }); container.register("FocusPresenter", { useClass: FocusPresenterImpl }); container.register("FollowKeyRepository", { useClass: FollowKeyRepositoryImpl, diff --git a/src/content/operators/impls/FindNextOperator.ts b/src/content/operators/impls/FindNextOperator.ts deleted file mode 100644 index c67f6d9..0000000 --- a/src/content/operators/impls/FindNextOperator.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Operator from "../Operator"; -import FindMasterClient from "../../client/FindMasterClient"; - -export default class FindNextOperator implements Operator { - constructor( - private readonly findMasterClient: FindMasterClient, - private readonly repeat: number - ) {} - - async run(): Promise<void> { - for (let i = 0; i < this.repeat; ++i) { - this.findMasterClient.findNext(); - } - } -} diff --git a/src/content/operators/impls/FindOperatorFactoryChain.ts b/src/content/operators/impls/FindOperatorFactoryChain.ts deleted file mode 100644 index b3524c1..0000000 --- a/src/content/operators/impls/FindOperatorFactoryChain.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { inject, injectable } from "tsyringe"; -import Operator from "../Operator"; -import OperatorFactoryChain from "../OperatorFactoryChain"; -import FindNextOperator from "./FindNextOperator"; -import FindPrevOperator from "./FindPrevOperator"; -import FindMasterClient from "../../client/FindMasterClient"; -import * as operations from "../../../shared/operations"; - -@injectable() -export default class FindOperatorFactoryChain implements OperatorFactoryChain { - constructor( - @inject("FindMasterClient") - private readonly findMasterClient: FindMasterClient - ) {} - - create(op: operations.Operation, repeat: number): Operator | null { - switch (op.type) { - case operations.FIND_NEXT: - return new FindNextOperator(this.findMasterClient, repeat); - case operations.FIND_PREV: - return new FindPrevOperator(this.findMasterClient, repeat); - } - return null; - } -} diff --git a/src/content/operators/impls/FindPrevOperator.ts b/src/content/operators/impls/FindPrevOperator.ts deleted file mode 100644 index f73e605..0000000 --- a/src/content/operators/impls/FindPrevOperator.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Operator from "../Operator"; -import FindMasterClient from "../../client/FindMasterClient"; - -export default class FindPrevOperator implements Operator { - constructor( - private readonly findMasterClient: FindMasterClient, - private readonly repeat: number - ) {} - - async run(): Promise<void> { - for (let i = 0; i < this.repeat; ++i) { - this.findMasterClient.findPrev(); - } - } -} diff --git a/src/content/operators/impls/OperatorFactoryImpl.ts b/src/content/operators/impls/OperatorFactoryImpl.ts index 22b35c8..bc9bbee 100644 --- a/src/content/operators/impls/OperatorFactoryImpl.ts +++ b/src/content/operators/impls/OperatorFactoryImpl.ts @@ -7,7 +7,6 @@ import { Operation } from "../../../shared/operations"; import OperationClient from "../../client/OperationClient"; import AddonOperatorFactoryChain from "./AddonOperatorFactoryChain"; import ClipboardOperatorFactoryChain from "./ClipboardOperatorFactoryChain"; -import FindOperatorFactoryChain from "./FindOperatorFactoryChain"; import FocusOperatorFactoryChain from "./FocusOperatorFactoryChain"; import FollowOperatorFactoryChain from "./FollowOperatorFactoryChain"; import MarkOperatorFactoryChain from "./MarkOperatorFactoryChain"; @@ -20,7 +19,6 @@ export default class OperatorFactoryImpl implements OperatorFactory { constructor( addonOperatorFactoryChain: AddonOperatorFactoryChain, clipboardOperatorFactoryChain: ClipboardOperatorFactoryChain, - findOperatorFactoryChain: FindOperatorFactoryChain, focusOperatorFactoryChain: FocusOperatorFactoryChain, followOperatorFactoryChain: FollowOperatorFactoryChain, markOperatorFactoryChain: MarkOperatorFactoryChain, @@ -31,7 +29,6 @@ export default class OperatorFactoryImpl implements OperatorFactory { this.factoryChains = [ addonOperatorFactoryChain, clipboardOperatorFactoryChain, - findOperatorFactoryChain, focusOperatorFactoryChain, followOperatorFactoryChain, markOperatorFactoryChain, diff --git a/src/content/presenters/FindPresenter.ts b/src/content/presenters/FindPresenter.ts deleted file mode 100644 index b25190c..0000000 --- a/src/content/presenters/FindPresenter.ts +++ /dev/null @@ -1,29 +0,0 @@ -export default interface FindPresenter { - find(keyword: string, backwards: boolean): boolean; - - clearSelection(): void; -} - -export class FindPresenterImpl implements FindPresenter { - find(keyword: string, backwards: boolean): boolean { - const caseSensitive = false; - const wrapScan = true; - - // NOTE: aWholeWord dows not implemented, and aSearchInFrames does not work - // because of same origin policy - const found = window.find(keyword, caseSensitive, backwards, wrapScan); - if (found) { - return found; - } - this.clearSelection(); - - return window.find(keyword, caseSensitive, backwards, wrapScan); - } - - clearSelection(): void { - const sel = window.getSelection(); - if (sel) { - sel.removeAllRanges(); - } - } -} diff --git a/src/content/repositories/FindRepository.ts b/src/content/repositories/FindRepository.ts deleted file mode 100644 index aeb200f..0000000 --- a/src/content/repositories/FindRepository.ts +++ /dev/null @@ -1,17 +0,0 @@ -export default interface FindRepository { - getLastKeyword(): string | null; - - setLastKeyword(keyword: string): void; -} - -let current: string | null = null; - -export class FindRepositoryImpl implements FindRepository { - getLastKeyword(): string | null { - return current; - } - - setLastKeyword(keyword: string): void { - current = keyword; - } -} diff --git a/src/content/usecases/FindUseCase.ts b/src/content/usecases/FindUseCase.ts deleted file mode 100644 index bff0eee..0000000 --- a/src/content/usecases/FindUseCase.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { injectable, inject } from "tsyringe"; -import FindPresenter from "../presenters/FindPresenter"; -import FindRepository from "../repositories/FindRepository"; -import FindClient from "../client/FindClient"; -import ConsoleClient from "../client/ConsoleClient"; - -@injectable() -export default class FindUseCase { - constructor( - @inject("FindPresenter") private presenter: FindPresenter, - @inject("FindRepository") private repository: FindRepository, - @inject("FindClient") private client: FindClient, - @inject("ConsoleClient") private consoleClient: ConsoleClient - ) {} - - async startFind(keyword?: string): Promise<void> { - this.presenter.clearSelection(); - if (keyword) { - this.saveKeyword(keyword); - } else { - const lastKeyword = await this.getKeyword(); - if (!lastKeyword) { - return this.showNoLastKeywordError(); - } - this.saveKeyword(lastKeyword); - } - return this.findNext(); - } - - findNext(): Promise<void> { - return this.findNextPrev(false); - } - - findPrev(): Promise<void> { - return this.findNextPrev(true); - } - - private async findNextPrev(backwards: boolean): Promise<void> { - const keyword = await this.getKeyword(); - if (!keyword) { - return this.showNoLastKeywordError(); - } - const found = this.presenter.find(keyword, backwards); - if (found) { - this.consoleClient.info("Pattern found: " + keyword); - } else { - this.consoleClient.error("Pattern not found: " + keyword); - } - } - - private async getKeyword(): Promise<string | null> { - let keyword = this.repository.getLastKeyword(); - if (!keyword) { - keyword = await this.client.getGlobalLastKeyword(); - } - return keyword; - } - - private async saveKeyword(keyword: string): Promise<void> { - this.repository.setLastKeyword(keyword); - await this.client.setGlobalLastKeyword(keyword); - } - - private async showNoLastKeywordError(): Promise<void> { - await this.consoleClient.error("No previous search keywords"); - } -} diff --git a/src/shared/messages.ts b/src/shared/messages.ts index 59329e7..2ad3b48 100644 --- a/src/shared/messages.ts +++ b/src/shared/messages.ts @@ -35,11 +35,6 @@ export const MARK_JUMP_GLOBAL = "mark.jump.global"; export const TAB_SCROLL_TO = "tab.scroll.to"; -export const FIND_NEXT = "find.next"; -export const FIND_PREV = "find.prev"; -export const FIND_GET_KEYWORD = "find.get.keyword"; -export const FIND_SET_KEYWORD = "find.set.keyword"; - export const ADDON_ENABLED_QUERY = "addon.enabled.query"; export const ADDON_ENABLED_RESPONSE = "addon.enabled.response"; export const ADDON_TOGGLE_ENABLED = "addon.toggle.enabled"; @@ -227,24 +222,6 @@ export interface TabScrollToMessage { y: number; } -export interface FindNextMessage { - type: typeof FIND_NEXT; -} - -export interface FindPrevMessage { - type: typeof FIND_PREV; -} - -export interface FindGetKeywordMessage { - type: typeof FIND_GET_KEYWORD; -} - -export interface FindSetKeywordMessage { - type: typeof FIND_SET_KEYWORD; - keyword: string; - found: boolean; -} - export interface AddonEnabledQueryMessage { type: typeof ADDON_ENABLED_QUERY; } @@ -322,10 +299,6 @@ export type Message = | MarkSetGlobalMessage | MarkJumpGlobalMessage | TabScrollToMessage - | FindNextMessage - | FindPrevMessage - | FindGetKeywordMessage - | FindSetKeywordMessage | AddonEnabledQueryMessage | AddonEnabledResponseMessage | AddonToggleEnabledMessage @@ -360,10 +333,6 @@ export const valueOf = (o: any): Message => { case MARK_SET_GLOBAL: case MARK_JUMP_GLOBAL: case TAB_SCROLL_TO: - case FIND_NEXT: - case FIND_PREV: - case FIND_GET_KEYWORD: - case FIND_SET_KEYWORD: case ADDON_ENABLED_QUERY: case ADDON_ENABLED_RESPONSE: case ADDON_TOGGLE_ENABLED: |