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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
import { injectable, inject } from 'tsyringe';
import * as operations from '../../shared/operations';
import KeymapUseCase from '../usecases/KeymapUseCase';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
import FindSlaveUseCase from '../usecases/FindSlaveUseCase';
import ScrollUseCase from '../usecases/ScrollUseCase';
import FocusUseCase from '../usecases/FocusUseCase';
import ClipboardUseCase from '../usecases/ClipboardUseCase';
import BackgroundClient from '../client/BackgroundClient';
import MarkKeyyUseCase from '../usecases/MarkKeyUseCase';
import FollowMasterClient from '../client/FollowMasterClient';
import Key from '../domains/Key';
@injectable()
export default class KeymapController {
constructor(
private keymapUseCase: KeymapUseCase,
private addonEnabledUseCase: AddonEnabledUseCase,
private findSlaveUseCase: FindSlaveUseCase,
private scrollUseCase: ScrollUseCase,
private focusUseCase: FocusUseCase,
private clipbaordUseCase: ClipboardUseCase,
private backgroundClient: BackgroundClient,
private markKeyUseCase: MarkKeyyUseCase,
@inject('FollowMasterClient')
private followMasterClient: FollowMasterClient,
) {
}
// eslint-disable-next-line complexity, max-lines-per-function
press(key: Key): boolean {
let op = this.keymapUseCase.nextOp(key);
if (op === null) {
return false;
}
// do not await due to return a boolean immediately
switch (op.type) {
case operations.ADDON_ENABLE:
this.addonEnabledUseCase.enable();
break;
case operations.ADDON_DISABLE:
this.addonEnabledUseCase.disable();
break;
case operations.ADDON_TOGGLE_ENABLED:
this.addonEnabledUseCase.toggle();
break;
case operations.FIND_NEXT:
this.findSlaveUseCase.findNext();
break;
case operations.FIND_PREV:
this.findSlaveUseCase.findPrev();
break;
case operations.SCROLL_VERTICALLY:
this.scrollUseCase.scrollVertically(op.count);
break;
case operations.SCROLL_HORIZONALLY:
this.scrollUseCase.scrollHorizonally(op.count);
break;
case operations.SCROLL_PAGES:
this.scrollUseCase.scrollPages(op.count);
break;
case operations.SCROLL_TOP:
this.scrollUseCase.scrollToTop();
break;
case operations.SCROLL_BOTTOM:
this.scrollUseCase.scrollToBottom();
break;
case operations.SCROLL_HOME:
this.scrollUseCase.scrollToHome();
break;
case operations.SCROLL_END:
this.scrollUseCase.scrollToEnd();
break;
case operations.FOLLOW_START:
this.followMasterClient.startFollow(op.newTab, op.background);
break;
case operations.MARK_SET_PREFIX:
this.markKeyUseCase.enableSetMode();
break;
case operations.MARK_JUMP_PREFIX:
this.markKeyUseCase.enableJumpMode();
break;
case operations.FOCUS_INPUT:
this.focusUseCase.focusFirstInput();
break;
case operations.URLS_YANK:
this.clipbaordUseCase.yankCurrentURL();
break;
case operations.URLS_PASTE:
this.clipbaordUseCase.openOrSearch(
op.newTab ? op.newTab : false,
);
break;
default:
this.backgroundClient.execBackgroundOp(op);
}
return true;
}
}
|