aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/components/common')
-rw-r--r--src/content/components/common/follow.ts2
-rw-r--r--src/content/components/common/index.ts12
-rw-r--r--src/content/components/common/keymapper.ts87
-rw-r--r--src/content/components/common/mark.ts6
4 files changed, 10 insertions, 97 deletions
diff --git a/src/content/components/common/follow.ts b/src/content/components/common/follow.ts
index e0003e3..413244e 100644
--- a/src/content/components/common/follow.ts
+++ b/src/content/components/common/follow.ts
@@ -1,7 +1,7 @@
import MessageListener from '../../MessageListener';
import { LinkHint, InputHint } from '../../presenters/Hint';
import * as messages from '../../../shared/messages';
-import { Key } from '../../../shared/utils/keys';
+import Key from '../../domains/Key';
import TabsClient, { TabsClientImpl } from '../../client/TabsClient';
import FollowMasterClient, { FollowMasterClientImpl }
from '../../client/FollowMasterClient';
diff --git a/src/content/components/common/index.ts b/src/content/components/common/index.ts
index c74020e..1aacf51 100644
--- a/src/content/components/common/index.ts
+++ b/src/content/components/common/index.ts
@@ -1,11 +1,11 @@
import InputDriver from './../../InputDriver';
import FollowComponent from './follow';
import MarkComponent from './mark';
-import KeymapperComponent from './keymapper';
+// import KeymapperComponent from './keymapper';
import * as messages from '../../../shared/messages';
import MessageListener from '../../MessageListener';
import * as blacklists from '../../../shared/blacklists';
-import * as keys from '../../../shared/utils/keys';
+import Key from '../../domains/Key';
import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
import SettingUseCase from '../../usecases/SettingUseCase';
@@ -18,11 +18,11 @@ export default class Common {
const input = new InputDriver(win.document.body);
const follow = new FollowComponent();
const mark = new MarkComponent(store);
- const keymapper = new KeymapperComponent(store);
+ // const keymapper = new KeymapperComponent(store);
- input.onKey((key: keys.Key) => follow.key(key));
- input.onKey((key: keys.Key) => mark.key(key));
- input.onKey((key: keys.Key) => keymapper.key(key));
+ input.onKey((key: Key) => follow.key(key));
+ input.onKey((key: Key) => mark.key(key));
+ // input.onKey((key: Key) => keymapper.key(key));
this.reloadSettings();
diff --git a/src/content/components/common/keymapper.ts b/src/content/components/common/keymapper.ts
deleted file mode 100644
index c901ffe..0000000
--- a/src/content/components/common/keymapper.ts
+++ /dev/null
@@ -1,87 +0,0 @@
-import * as inputActions from '../../actions/input';
-import * as operationActions from '../../actions/operation';
-import * as operations from '../../../shared/operations';
-import * as keyUtils from '../../../shared/utils/keys';
-
-import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
-import { SettingRepositoryImpl } from '../../repositories/SettingRepository';
-import { Keymaps } from '../../../shared/Settings';
-
-type KeymapEntityMap = Map<keyUtils.Key[], operations.Operation>;
-
-let addonEnabledUseCase = new AddonEnabledUseCase();
-let settingRepository = new SettingRepositoryImpl();
-
-const reservedKeymaps: Keymaps = {
- '<Esc>': { type: operations.CANCEL },
- '<C-[>': { type: operations.CANCEL },
-};
-
-const mapStartsWith = (
- mapping: keyUtils.Key[],
- keys: keyUtils.Key[],
-): boolean => {
- if (mapping.length < keys.length) {
- return false;
- }
- for (let i = 0; i < keys.length; ++i) {
- if (!keyUtils.equals(mapping[i], keys[i])) {
- return false;
- }
- }
- return true;
-};
-
-export default class KeymapperComponent {
- private store: any;
-
- constructor(store: any) {
- this.store = store;
- }
-
- key(key: keyUtils.Key): boolean {
- this.store.dispatch(inputActions.keyPress(key));
-
- let input = this.store.getState().input;
- let keymaps = this.keymapEntityMap();
- let matched = Array.from(keymaps.keys()).filter(
- (mapping: keyUtils.Key[]) => {
- return mapStartsWith(mapping, input.keys);
- });
- if (!addonEnabledUseCase.getEnabled()) {
- // available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if
- // the addon disabled
- matched = matched.filter((keys) => {
- let type = (keymaps.get(keys) as operations.Operation).type;
- return type === operations.ADDON_ENABLE ||
- type === operations.ADDON_TOGGLE_ENABLED;
- });
- }
- if (matched.length === 0) {
- this.store.dispatch(inputActions.clearKeys());
- return false;
- } else if (matched.length > 1 ||
- matched.length === 1 && input.keys.length < matched[0].length) {
- return true;
- }
- let operation = keymaps.get(matched[0]) as operations.Operation;
- let act = operationActions.exec(operation);
- this.store.dispatch(act);
- this.store.dispatch(inputActions.clearKeys());
- return true;
- }
-
- private keymapEntityMap(): KeymapEntityMap {
- let keymaps = {
- ...settingRepository.get().keymaps,
- ...reservedKeymaps,
- };
- let entries = Object.entries(keymaps).map((entry) => {
- return [
- keyUtils.fromMapKeys(entry[0]),
- entry[1],
- ];
- }) as [keyUtils.Key[], operations.Operation][];
- return new Map<keyUtils.Key[], operations.Operation>(entries);
- }
-}
diff --git a/src/content/components/common/mark.ts b/src/content/components/common/mark.ts
index eec95d6..058b873 100644
--- a/src/content/components/common/mark.ts
+++ b/src/content/components/common/mark.ts
@@ -1,12 +1,12 @@
import * as markActions from '../../actions/mark';
import * as consoleFrames from '../..//console-frames';
-import * as keyUtils from '../../../shared/utils/keys';
+import Key from '../../domains/Key';
import MarkUseCase from '../../usecases/MarkUseCase';
let markUseCase = new MarkUseCase();
-const cancelKey = (key: keyUtils.Key): boolean => {
+const cancelKey = (key: Key): boolean => {
return key.key === 'Esc' || key.key === '[' && Boolean(key.ctrlKey);
};
@@ -18,7 +18,7 @@ export default class MarkComponent {
}
// eslint-disable-next-line max-statements
- key(key: keyUtils.Key) {
+ key(key: Key) {
let { mark: markState } = this.store.getState();
if (!markState.setMode && !markState.jumpMode) {