aboutsummaryrefslogtreecommitdiff
path: root/src/content/controllers/MarkKeyController.ts
blob: 395dee3fc84877c072985ca714986863939bf549 (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
30
31
import MarkUseCase from '../usecases/MarkUseCase';
import MarkKeyyUseCase from '../usecases/MarkKeyUseCase';
import Key from '../domains/Key';

export default class MarkKeyController {
  private markUseCase: MarkUseCase;

  private markKeyUseCase: MarkKeyyUseCase;

  constructor({
    markUseCase = new MarkUseCase(),
    markKeyUseCase = new MarkKeyyUseCase(),
  } = {}) {
    this.markUseCase = markUseCase;
    this.markKeyUseCase = markKeyUseCase;
  }

  press(key: Key): boolean {
    if (this.markKeyUseCase.isSetMode()) {
      this.markUseCase.set(key.key);
      this.markKeyUseCase.disableSetMode();
      return true;
    }
    if (this.markKeyUseCase.isJumpMode()) {
      this.markUseCase.jump(key.key);
      this.markKeyUseCase.disableJumpMode();
      return true;
    }
    return false;
  }
}