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.js9
-rw-r--r--src/content/components/common/index.js19
-rw-r--r--src/content/components/common/input.js6
3 files changed, 30 insertions, 4 deletions
diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.js
index 42dd897..2a55ea3 100644
--- a/src/content/components/common/follow.js
+++ b/src/content/components/common/follow.js
@@ -50,6 +50,7 @@ export default class Follow {
this.win = win;
this.store = store;
this.newTab = false;
+ this.background = false;
this.hints = {};
this.targets = [];
@@ -63,6 +64,7 @@ export default class Follow {
this.win.parent.postMessage(JSON.stringify({
type: messages.FOLLOW_KEY_PRESS,
key: key.key,
+ ctrlKey: key.ctrlKey,
}), '*');
return true;
}
@@ -84,6 +86,7 @@ export default class Follow {
type: messages.OPEN_URL,
url: element.href,
newTab: true,
+ background: this.background,
});
}
@@ -95,12 +98,13 @@ export default class Follow {
}), '*');
}
- createHints(keysArray, newTab) {
+ createHints(keysArray, newTab, background) {
if (keysArray.length !== this.targets.length) {
throw new Error('illegal hint count');
}
this.newTab = newTab;
+ this.background = background;
this.hints = {};
for (let i = 0; i < keysArray.length; ++i) {
let keys = keysArray[i];
@@ -166,7 +170,8 @@ export default class Follow {
case messages.FOLLOW_REQUEST_COUNT_TARGETS:
return this.countHints(sender, message.viewSize, message.framePosition);
case messages.FOLLOW_CREATE_HINTS:
- return this.createHints(message.keysArray, message.newTab);
+ return this.createHints(
+ message.keysArray, message.newTab, message.background);
case messages.FOLLOW_SHOW_HINTS:
return this.showHints(message.keys);
case messages.FOLLOW_ACTIVATE:
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js
index 565632c..9b7b083 100644
--- a/src/content/components/common/index.js
+++ b/src/content/components/common/index.js
@@ -3,6 +3,7 @@ import KeymapperComponent from './keymapper';
import FollowComponent from './follow';
import * as settingActions from 'content/actions/setting';
import messages from 'shared/messages';
+import * as addonActions from '../../actions/addon';
export default class Common {
constructor(win, store) {
@@ -14,16 +15,32 @@ export default class Common {
input.onKey(key => keymapper.key(key));
this.store = store;
+ this.prevEnabled = undefined;
this.reloadSettings();
messages.onMessage(this.onMessage.bind(this));
+ store.subscribe(() => this.update());
}
onMessage(message) {
switch (message.type) {
case messages.SETTINGS_CHANGED:
- this.reloadSettings();
+ return this.reloadSettings();
+ case messages.ADDON_TOGGLE_ENABLED:
+ return this.store.dispatch(addonActions.toggleEnabled());
+ }
+ }
+
+ update() {
+ let enabled = this.store.getState().addon.enabled;
+ if (enabled !== this.prevEnabled) {
+ this.prevEnabled = enabled;
+
+ browser.runtime.sendMessage({
+ type: messages.ADDON_ENABLED_RESPONSE,
+ enabled,
+ });
}
}
diff --git a/src/content/components/common/input.js b/src/content/components/common/input.js
index 22b0a91..eefaf10 100644
--- a/src/content/components/common/input.js
+++ b/src/content/components/common/input.js
@@ -1,6 +1,10 @@
import * as dom from 'shared/utils/dom';
import * as keys from 'shared/utils/keys';
+const cancelKey = (e) => {
+ return e.key === 'Escape' || e.key === '[' && e.ctrlKey;
+};
+
export default class InputComponent {
constructor(target) {
this.pressed = {};
@@ -37,7 +41,7 @@ export default class InputComponent {
capture(e) {
if (this.fromInput(e)) {
- if (e.key === 'Escape' && e.target.blur) {
+ if (cancelKey(e) && e.target.blur) {
e.target.blur();
}
return;