diff options
Diffstat (limited to 'src/content/usecases/KeymapUseCase.ts')
-rw-r--r-- | src/content/usecases/KeymapUseCase.ts | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index e02bc48..3cbadcb 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -1,16 +1,16 @@ -import { injectable, inject } from 'tsyringe'; -import KeymapRepository from '../repositories/KeymapRepository'; -import SettingRepository from '../repositories/SettingRepository'; -import AddonEnabledRepository from '../repositories/AddonEnabledRepository'; -import * as operations from '../../shared/operations'; -import Keymaps from '../../shared/settings/Keymaps'; -import Key from '../../shared/settings/Key'; -import KeySequence from '../domains/KeySequence'; -import AddressRepository from '../repositories/AddressRepository'; +import { injectable, inject } from "tsyringe"; +import KeymapRepository from "../repositories/KeymapRepository"; +import SettingRepository from "../repositories/SettingRepository"; +import AddonEnabledRepository from "../repositories/AddonEnabledRepository"; +import * as operations from "../../shared/operations"; +import Keymaps from "../../shared/settings/Keymaps"; +import Key from "../../shared/settings/Key"; +import KeySequence from "../domains/KeySequence"; +import AddressRepository from "../repositories/AddressRepository"; const reservedKeymaps = Keymaps.fromJSON({ - '<Esc>': { type: operations.CANCEL }, - '<C-[>': { type: operations.CANCEL }, + "<Esc>": { type: operations.CANCEL }, + "<C-[>": { type: operations.CANCEL }, }); const enableAddonOps = [ @@ -21,22 +21,21 @@ const enableAddonOps = [ @injectable() export default class KeymapUseCase { constructor( - @inject('KeymapRepository') + @inject("KeymapRepository") private repository: KeymapRepository, - @inject('SettingRepository') + @inject("SettingRepository") private settingRepository: SettingRepository, - @inject('AddonEnabledRepository') + @inject("AddonEnabledRepository") private addonEnabledRepository: AddonEnabledRepository, - @inject('AddressRepository') - private addressRepository: AddressRepository, - ) { - } + @inject("AddressRepository") + private addressRepository: AddressRepository + ) {} // eslint-disable-next-line max-statements - nextOps(key: Key): { repeat: number, op: operations.Operation } | null { + nextOps(key: Key): { repeat: number; op: operations.Operation } | null { const sequence = this.repository.enqueueKey(key); const baseSequence = sequence.trimNumericPrefix(); const keymaps = this.keymapEntityMap(); @@ -49,14 +48,14 @@ export default class KeymapUseCase { return null; } - if (matched.length === 1 && - sequence.length() === matched[0][0].length()) { + if (matched.length === 1 && sequence.length() === matched[0][0].length()) { // keys are matched with an operation this.repository.clear(); return { repeat: 1, op: matched[0][1] }; } else if ( baseMatched.length === 1 && - baseSequence.length() === baseMatched[0][0].length()) { + baseSequence.length() === baseMatched[0][0].length() + ) { // keys are matched with an operation with a numeric prefix this.repository.clear(); return { repeat: sequence.repeatCount(), op: baseMatched[0][1] }; @@ -75,15 +74,20 @@ export default class KeymapUseCase { } private keymapEntityMap(): [KeySequence, operations.Operation][] { - const keymaps = this.settingRepository.get().keymaps.combine(reservedKeymaps); - let entries = keymaps.entries().map( - ([keys, op]) => [KeySequence.fromMapKeys(keys), op] - ) as [KeySequence, operations.Operation][]; + const keymaps = this.settingRepository + .get() + .keymaps.combine(reservedKeymaps); + let entries = keymaps + .entries() + .map(([keys, op]) => [KeySequence.fromMapKeys(keys), op]) as [ + KeySequence, + operations.Operation + ][]; if (!this.addonEnabledRepository.get()) { // available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if // the addon disabled - entries = entries.filter( - ([_seq, { type }]) => enableAddonOps.includes(type) + entries = entries.filter(([_seq, { type }]) => + enableAddonOps.includes(type) ); } return entries; |