aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-21 21:17:27 +0900
committerGitHub <noreply@github.com>2017-10-21 21:17:27 +0900
commit7639e99b755e372712dca36e077a85d9a025cd9f (patch)
tree177a523e5996e302d647853cf4b11767e669de3c /src
parent941073404b534d7f79e90f29b514a5f06fb8080d (diff)
parent6ad143d294df0a0cc2dfb775ecab9f8b12ee7be5 (diff)
Merge pull request #86 from ueokande/10-disable-temporary
Disable add-on temporary
Diffstat (limited to 'src')
-rw-r--r--src/content/actions/addon.js15
-rw-r--r--src/content/actions/index.js4
-rw-r--r--src/content/actions/input.js11
-rw-r--r--src/content/actions/operation.js7
-rw-r--r--src/content/components/common/index.js4
-rw-r--r--src/content/components/common/input.js29
-rw-r--r--src/content/components/common/keymapper.js16
-rw-r--r--src/content/reducers/addon.js24
-rw-r--r--src/content/reducers/index.js3
-rw-r--r--src/shared/default-settings.js3
-rw-r--r--src/shared/operations.js5
11 files changed, 101 insertions, 20 deletions
diff --git a/src/content/actions/addon.js b/src/content/actions/addon.js
new file mode 100644
index 0000000..8d38025
--- /dev/null
+++ b/src/content/actions/addon.js
@@ -0,0 +1,15 @@
+import actions from 'content/actions';
+
+const enable = () => {
+ return { type: actions.ADDON_ENABLE };
+};
+
+const disable = () => {
+ return { type: actions.ADDON_DISABLE };
+};
+
+const toggleEnabled = () => {
+ return { type: actions.ADDON_TOGGLE_ENABLED };
+};
+
+export { enable, disable, toggleEnabled };
diff --git a/src/content/actions/index.js b/src/content/actions/index.js
index f8db948..085d510 100644
--- a/src/content/actions/index.js
+++ b/src/content/actions/index.js
@@ -1,5 +1,9 @@
export default {
// User input
+ ADDON_ENABLE: 'addon.enable',
+ ADDON_DISABLE: 'addon.disable',
+ ADDON_TOGGLE_ENABLED: 'addon.toggle.enabled',
+
INPUT_KEY_PRESS: 'input.key,press',
INPUT_CLEAR_KEYS: 'input.clear.keys',
INPUT_SET_KEYMAPS: 'input.set.keymaps',
diff --git a/src/content/actions/input.js b/src/content/actions/input.js
index 10ff835..31cfee3 100644
--- a/src/content/actions/input.js
+++ b/src/content/actions/input.js
@@ -1,16 +1,9 @@
import actions from 'content/actions';
-const asKeymapChars = (key, ctrl) => {
- if (ctrl) {
- return '<C-' + key.toUpperCase() + '>';
- }
- return key;
-};
-
-const keyPress = (key, ctrl) => {
+const keyPress = (key) => {
return {
type: actions.INPUT_KEY_PRESS,
- key: asKeymapChars(key, ctrl),
+ key,
};
};
diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js
index 81bcc2f..897f361 100644
--- a/src/content/actions/operation.js
+++ b/src/content/actions/operation.js
@@ -4,9 +4,16 @@ import * as scrolls from 'content/scrolls';
import * as navigates from 'content/navigates';
import * as urls from 'content/urls';
import * as consoleFrames from 'content/console-frames';
+import * as addonActions from './addon';
const exec = (operation) => {
switch (operation.type) {
+ case operations.ADDON_ENABLE:
+ return addonActions.enable();
+ case operations.ADDON_DISABLE:
+ return addonActions.disable();
+ case operations.ADDON_TOGGLE_ENABLED:
+ return addonActions.toggleEnabled();
case operations.SCROLL_VERTICALLY:
return scrolls.scrollVertically(window, operation.count);
case operations.SCROLL_HORIZONALLY:
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js
index 98a2337..db0ac43 100644
--- a/src/content/components/common/index.js
+++ b/src/content/components/common/index.js
@@ -10,8 +10,8 @@ export default class Common {
const input = new InputComponent(win.document.body, store);
const keymapper = new KeymapperComponent(store);
- input.onKey((key, ctrl) => follow.key(key, ctrl));
- input.onKey((key, ctrl) => keymapper.key(key, ctrl));
+ input.onKey(key => follow.key(key));
+ input.onKey(key => keymapper.key(key));
this.store = store;
this.children = [
diff --git a/src/content/components/common/input.js b/src/content/components/common/input.js
index df09894..f285b0c 100644
--- a/src/content/components/common/input.js
+++ b/src/content/components/common/input.js
@@ -1,3 +1,21 @@
+const modifierdKeyName = (name) => {
+ if (name.length === 1) {
+ return name.toUpperCase();
+ } else if (name === 'Escape') {
+ return 'Esc';
+ }
+ return name;
+};
+
+const mapKey = (e) => {
+ if (e.ctrlKey) {
+ return '<C-' + modifierdKeyName(e.key) + '>';
+ } else if (e.shiftKey && e.key.length !== 1) {
+ return '<S-' + modifierdKeyName(e.key) + '>';
+ }
+ return e.key;
+};
+
export default class InputComponent {
constructor(target) {
this.pressed = {};
@@ -47,17 +65,16 @@ export default class InputComponent {
return;
}
- let stop = false;
+ let key = mapKey(e);
+
for (let listener of this.onKeyListeners) {
- stop = stop || listener(e.key, e.ctrlKey);
+ let stop = listener(key);
if (stop) {
+ e.preventDefault();
+ e.stopPropagation();
break;
}
}
- if (stop) {
- e.preventDefault();
- e.stopPropagation();
- }
}
fromInput(e) {
diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js
index 655c3f2..5070cd8 100644
--- a/src/content/components/common/keymapper.js
+++ b/src/content/components/common/keymapper.js
@@ -1,5 +1,6 @@
import * as inputActions from 'content/actions/input';
import * as operationActions from 'content/actions/operation';
+import operations from 'shared/operations';
export default class KeymapperComponent {
constructor(store) {
@@ -9,13 +10,24 @@ export default class KeymapperComponent {
update() {
}
- key(key, ctrl) {
- this.store.dispatch(inputActions.keyPress(key, ctrl));
+ key(key) {
+ let enabled = this.store.getState().addon.enabled;
+
+ this.store.dispatch(inputActions.keyPress(key));
let input = this.store.getState().input;
let matched = Object.keys(input.keymaps).filter((keyStr) => {
return keyStr.startsWith(input.keys);
});
+ if (!enabled) {
+ // available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if
+ // the addon disabled
+ matched = matched.filter((keys) => {
+ let type = input.keymaps[keys].type;
+ return type === operations.ADDON_ENABLE ||
+ type === operations.ADDON_TOGGLE_ENABLED;
+ });
+ }
if (matched.length === 0) {
this.store.dispatch(inputActions.clearKeys());
return false;
diff --git a/src/content/reducers/addon.js b/src/content/reducers/addon.js
new file mode 100644
index 0000000..8cc5ef1
--- /dev/null
+++ b/src/content/reducers/addon.js
@@ -0,0 +1,24 @@
+import actions from 'content/actions';
+
+const defaultState = {
+ enabled: true,
+};
+
+export default function reducer(state = defaultState, action = {}) {
+ switch (action.type) {
+ case actions.ADDON_ENABLE:
+ return Object.assign({}, state, {
+ enabled: true,
+ });
+ case actions.ADDON_DISABLE:
+ return Object.assign({}, state, {
+ enabled: false,
+ });
+ case actions.ADDON_TOGGLE_ENABLED:
+ return Object.assign({}, state, {
+ enabled: !state.enabled,
+ });
+ default:
+ return state;
+ }
+}
diff --git a/src/content/reducers/index.js b/src/content/reducers/index.js
index c026a19..7cf318e 100644
--- a/src/content/reducers/index.js
+++ b/src/content/reducers/index.js
@@ -1,14 +1,17 @@
+import addonReducer from './addon';
import inputReducer from './input';
import followReducer from './follow';
// Make setting reducer instead of re-use
const defaultState = {
+ addon: addonReducer(undefined, {}),
input: inputReducer(undefined, {}),
follow: followReducer(undefined, {}),
};
export default function reducer(state = defaultState, action = {}) {
return Object.assign({}, state, {
+ addon: addonReducer(state.addon, action),
input: inputReducer(state.input, action),
follow: followReducer(state.follow, action),
});
diff --git a/src/shared/default-settings.js b/src/shared/default-settings.js
index d280185..60e7876 100644
--- a/src/shared/default-settings.js
+++ b/src/shared/default-settings.js
@@ -41,7 +41,8 @@ export default {
"]]": { "type": "navigate.link.next" },
"gu": { "type": "navigate.parent" },
"gU": { "type": "navigate.root" },
- "y": { "type": "urls.yank" }
+ "y": { "type": "urls.yank" },
+ "<S-Esc>": { "type": "addon.toggle.enabled" }
},
"search": {
"default": "google",
diff --git a/src/shared/operations.js b/src/shared/operations.js
index 0d2a381..d5c2985 100644
--- a/src/shared/operations.js
+++ b/src/shared/operations.js
@@ -1,4 +1,9 @@
export default {
+ // Addons
+ ADDON_ENABLE: 'addon.enable',
+ ADDON_DISABLE: 'addon.disable',
+ ADDON_TOGGLE_ENABLED: 'addon.toggle.enabled',
+
// Command
COMMAND_SHOW: 'command.show',
COMMAND_SHOW_OPEN: 'command.show.open',