aboutsummaryrefslogtreecommitdiff
path: root/src/content/presenters/FindPresenter.ts
blob: b25190c1b9591bb66ce549a59e4b05734746f526 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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();
    }
  }
}