aboutsummaryrefslogtreecommitdiff
path: root/src/content/usecases/KeymapUseCase.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-05-02 17:25:56 +0900
committerGitHub <noreply@github.com>2020-05-02 17:25:56 +0900
commit5df0537bcf65a341e79852b1b30379c73318529c (patch)
treeaee5efe52412855f620cb514a13a2c14373f27b7 /src/content/usecases/KeymapUseCase.ts
parent685f2b7b69218b06b5bb676069e35f79c5048c9b (diff)
parent75abd90ecb8201ad845b266f96220d8adfe19b2d (diff)
Merge pull request #749 from ueokande/qa-0.28
QA 0.28
Diffstat (limited to 'src/content/usecases/KeymapUseCase.ts')
-rw-r--r--src/content/usecases/KeymapUseCase.ts60
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;