aboutsummaryrefslogtreecommitdiff
path: root/src/content/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/components')
-rw-r--r--src/content/components/common/index.js7
-rw-r--r--src/content/components/common/mark.js74
-rw-r--r--src/content/components/top-content/index.js3
3 files changed, 82 insertions, 2 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js
index a1e71a1..bcab4fa 100644
--- a/src/content/components/common/index.js
+++ b/src/content/components/common/index.js
@@ -1,6 +1,7 @@
import InputComponent from './input';
-import KeymapperComponent from './keymapper';
import FollowComponent from './follow';
+import MarkComponent from './mark';
+import KeymapperComponent from './keymapper';
import * as settingActions from 'content/actions/setting';
import messages from 'shared/messages';
import * as addonActions from '../../actions/addon';
@@ -8,11 +9,13 @@ import * as blacklists from 'shared/blacklists';
export default class Common {
constructor(win, store) {
- const follow = new FollowComponent(win, store);
const input = new InputComponent(win.document.body, store);
+ const follow = new FollowComponent(win, store);
+ const mark = new MarkComponent(win.document.body, store);
const keymapper = new KeymapperComponent(store);
input.onKey(key => follow.key(key));
+ input.onKey(key => mark.key(key));
input.onKey(key => keymapper.key(key));
this.win = win;
diff --git a/src/content/components/common/mark.js b/src/content/components/common/mark.js
new file mode 100644
index 0000000..1ed636b
--- /dev/null
+++ b/src/content/components/common/mark.js
@@ -0,0 +1,74 @@
+import * as markActions from 'content/actions/mark';
+import * as scrolls from 'content/scrolls';
+import * as consoleFrames from 'content/console-frames';
+import * as properties from 'shared/settings/properties';
+
+const cancelKey = (key) => {
+ return key.key === 'Esc' || key.key === '[' && key.ctrlKey;
+};
+
+const globalKey = (key) => {
+ return (/^[A-Z0-9]$/).test(key);
+};
+
+export default class MarkComponent {
+ constructor(body, store) {
+ this.body = body;
+ this.store = store;
+ }
+
+ // eslint-disable-next-line max-statements
+ key(key) {
+ let { mark: markStage, setting } = this.store.getState();
+ let smoothscroll = setting.properties.smoothscroll ||
+ properties.defaults.smoothscroll;
+
+ if (!markStage.setMode && !markStage.jumpMode) {
+ return false;
+ }
+
+ if (cancelKey(key)) {
+ this.store.dispatch(markActions.cancel());
+ return true;
+ }
+
+ if (key.ctrlKey || key.metaKey || key.altKey) {
+ consoleFrames.postError(window.document, 'Unknown mark');
+ } else if (globalKey(key.key) && markStage.setMode) {
+ this.doSetGlobal(key);
+ } else if (globalKey(key.key) && markStage.jumpMode) {
+ this.doJumpGlobal(key);
+ } else if (markStage.setMode) {
+ this.doSet(key);
+ } else if (markStage.jumpMode) {
+ this.doJump(markStage.marks, key, smoothscroll);
+ }
+
+ this.store.dispatch(markActions.cancel());
+ return true;
+ }
+
+ doSet(key) {
+ let { x, y } = scrolls.getScroll();
+ this.store.dispatch(markActions.setLocal(key.key, x, y));
+ }
+
+ doJump(marks, key, smoothscroll) {
+ if (!marks[key.key]) {
+ consoleFrames.postError(window.document, 'Mark is not set');
+ return;
+ }
+
+ let { x, y } = marks[key.key];
+ scrolls.scrollTo(x, y, smoothscroll);
+ }
+
+ doSetGlobal(key) {
+ let { x, y } = scrolls.getScroll();
+ this.store.dispatch(markActions.setGlobal(key.key, x, y));
+ }
+
+ doJumpGlobal(key) {
+ this.store.dispatch(markActions.jumpGlobal(key.key));
+ }
+}
diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.js
index e22e957..1aaef1b 100644
--- a/src/content/components/top-content/index.js
+++ b/src/content/components/top-content/index.js
@@ -3,6 +3,7 @@ import FollowController from './follow-controller';
import FindComponent from './find';
import * as consoleFrames from '../../console-frames';
import messages from 'shared/messages';
+import * as scrolls from 'content/scrolls';
export default class TopContent {
@@ -33,6 +34,8 @@ export default class TopContent {
type: messages.ADDON_ENABLED_RESPONSE,
enabled: addonState.enabled,
});
+ case messages.TAB_SCROLL_TO:
+ return scrolls.scrollTo(message.x, message.y, false);
}
}
}