diff options
Diffstat (limited to 'src/content/controllers')
-rw-r--r-- | src/content/controllers/KeymapController.ts | 125 |
1 files changed, 62 insertions, 63 deletions
diff --git a/src/content/controllers/KeymapController.ts b/src/content/controllers/KeymapController.ts index 6157a71..452e3d4 100644 --- a/src/content/controllers/KeymapController.ts +++ b/src/content/controllers/KeymapController.ts @@ -23,7 +23,7 @@ export default class KeymapController { private markKeyUseCase: MarkKeyyUseCase, @inject('OperationClient') - private backgroundClient: OperationClient, + private operationClient: OperationClient, @inject('FollowMasterClient') private followMasterClient: FollowMasterClient, @@ -32,71 +32,70 @@ export default class KeymapController { // eslint-disable-next-line complexity, max-lines-per-function press(key: Key): boolean { - let op = this.keymapUseCase.nextOp(key); - if (op === null) { + let nextOp = this.keymapUseCase.nextOps(key); + if (nextOp === 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); + if (!operations.isNRepeatable(nextOp.op.type)) { + nextOp.repeat = 1; + } + + const doFunc = ((op: operations.Operation) => { + switch (op.type) { + case operations.ADDON_ENABLE: + return () => this.addonEnabledUseCase.enable(); + case operations.ADDON_DISABLE: + return () => this.addonEnabledUseCase.disable(); + case operations.ADDON_TOGGLE_ENABLED: + return () => this.addonEnabledUseCase.toggle(); + case operations.FIND_NEXT: + return () => this.findSlaveUseCase.findNext(); + case operations.FIND_PREV: + return () => this.findSlaveUseCase.findPrev(); + case operations.SCROLL_VERTICALLY: + return () => this.scrollUseCase.scrollVertically(op.count); + case operations.SCROLL_HORIZONALLY: + return () => this.scrollUseCase.scrollHorizonally(op.count); + case operations.SCROLL_PAGES: + return () => this.scrollUseCase.scrollPages(op.count); + case operations.SCROLL_TOP: + return () => this.scrollUseCase.scrollToTop(); + case operations.SCROLL_BOTTOM: + return () => this.scrollUseCase.scrollToBottom(); + case operations.SCROLL_HOME: + return () => this.scrollUseCase.scrollToHome(); + case operations.SCROLL_END: + return () => this.scrollUseCase.scrollToEnd(); + case operations.FOLLOW_START: + return () => this.followMasterClient.startFollow( + op.newTab, op.background); + case operations.MARK_SET_PREFIX: + return () => this.markKeyUseCase.enableSetMode(); + case operations.MARK_JUMP_PREFIX: + return () => this.markKeyUseCase.enableJumpMode(); + case operations.FOCUS_INPUT: + return () => this.focusUseCase.focusFirstInput(); + case operations.URLS_YANK: + return () => this.clipbaordUseCase.yankCurrentURL(); + case operations.URLS_PASTE: + return () => this.clipbaordUseCase.openOrSearch( + op.newTab ? op.newTab : false, + ); + default: + return null; + } + })(nextOp.op); + + if (doFunc === null) { + // Do not await asynchronous methods to return a boolean immidiately. The + // caller requires the synchronous response from the callback to identify + // to continue of abandon the event propagations. + this.operationClient.execBackgroundOp(nextOp.repeat, nextOp.op); + } else { + for (let i = 0; i < nextOp.repeat; ++i) { + doFunc(); + } } return true; } |