diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-02-09 09:32:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-09 09:32:27 +0900 |
commit | 8b9388f6e60fe67d20638f55aecb0ed1b281871a (patch) | |
tree | 9fa6491a7e9d404351fe5cf436754b44fa713b0d | |
parent | f27cff5083b8ea7a6c316f4ed31ed6507bc99dc0 (diff) | |
parent | 0263170bd2603165edecce1b55493c7b2092e2e6 (diff) |
Merge pull request #709 from ueokande/blur-keys-on-blur
Clear keys on window blur
-rw-r--r-- | src/content/Application.ts | 7 | ||||
-rw-r--r-- | src/content/controllers/KeymapController.ts | 4 | ||||
-rw-r--r-- | src/content/usecases/KeymapUseCase.ts | 4 | ||||
-rw-r--r-- | src/shared/settings/Key.ts | 2 | ||||
-rw-r--r-- | test/shared/settings/Key.test.ts | 2 |
5 files changed, 17 insertions, 2 deletions
diff --git a/src/content/Application.ts b/src/content/Application.ts index cfa01fd..fbfeb6d 100644 --- a/src/content/Application.ts +++ b/src/content/Application.ts @@ -40,6 +40,7 @@ export default class Application { run() { this.routeCommonComponents(); + this.routeFocusEvents(); if (window.self === window.top) { this.routeMasterComponents(); } @@ -118,4 +119,10 @@ export default class Application { this.settingController.initSettings(); } + + private routeFocusEvents() { + window.addEventListener('blur', () => { + this.keymapController.onBlurWindow(); + }); + } } diff --git a/src/content/controllers/KeymapController.ts b/src/content/controllers/KeymapController.ts index f9c2545..639b4a1 100644 --- a/src/content/controllers/KeymapController.ts +++ b/src/content/controllers/KeymapController.ts @@ -99,4 +99,8 @@ export default class KeymapController { } return true; } + + onBlurWindow() { + this.keymapUseCase.cancel(); + } } diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index 7aa7e92..e02bc48 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -70,6 +70,10 @@ export default class KeymapUseCase { return null; } + cancel() { + this.repository.clear(); + } + private keymapEntityMap(): [KeySequence, operations.Operation][] { const keymaps = this.settingRepository.get().keymaps.combine(reservedKeymaps); let entries = keymaps.entries().map( diff --git a/src/shared/settings/Key.ts b/src/shared/settings/Key.ts index cfe1e7e..1464e57 100644 --- a/src/shared/settings/Key.ts +++ b/src/shared/settings/Key.ts @@ -60,7 +60,7 @@ export default class Key { } isDigit(): boolean { - return digits.includes(this.key); + return digits.includes(this.key) && !this.ctrl && !this.alt && !this.meta; } equals(key: Key) { diff --git a/test/shared/settings/Key.test.ts b/test/shared/settings/Key.test.ts index 3a1c86e..b8538f8 100644 --- a/test/shared/settings/Key.test.ts +++ b/test/shared/settings/Key.test.ts @@ -80,7 +80,7 @@ describe("Key", () => { it('returns true if the key is a digit', () => { expect(new Key({ key: '0' }).isDigit()).to.be.true; expect(new Key({ key: '9' }).isDigit()).to.be.true; - expect(new Key({ key: '9', shift: true }).isDigit()).to.be.true; + expect(new Key({ key: '9', alt: true }).isDigit()).to.be.false; expect(new Key({ key: 'a' }).isDigit()).to.be.false; expect(new Key({ key: '0' }).isDigit()).to.be.false; |