diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2021-07-29 22:29:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 22:29:40 +0900 |
commit | 5592b02a1500062628063862158116f382f3d8e2 (patch) | |
tree | 5c29d29a8fa1aa14f4f6407a66bcaf528c42555c /src/content/usecases | |
parent | 75236e9a41788f64df61b14a99e78aedc548e0ad (diff) | |
parent | 1160cf8aedf9810a76d84e3d99a72365e8aeae8a (diff) |
Merge pull request #1213 from ueokande/cross-frame-search
Cross frame search
Diffstat (limited to 'src/content/usecases')
-rw-r--r-- | src/content/usecases/FindUseCase.ts | 63 |
1 files changed, 9 insertions, 54 deletions
diff --git a/src/content/usecases/FindUseCase.ts b/src/content/usecases/FindUseCase.ts index bff0eee..9e77124 100644 --- a/src/content/usecases/FindUseCase.ts +++ b/src/content/usecases/FindUseCase.ts @@ -1,67 +1,22 @@ -import { injectable, inject } from "tsyringe"; +import { inject, injectable } 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 + @inject("FindPresenter") + private readonly findPresenter: FindPresenter ) {} - 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(keyword: string): boolean { + return this.findPresenter.find(keyword, false); } - findNext(): Promise<void> { - return this.findNextPrev(false); + findPrev(keyword: string): boolean { + return this.findPresenter.find(keyword, true); } - 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"); + clearSelection() { + this.findPresenter.clearSelection(); } } |