diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-10-11 17:42:38 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-10-11 17:42:38 +0900 |
commit | 6e6e306275a8ee5632a22b1e30c807bd5ae9cc7e (patch) | |
tree | ae58967f2973621eeb6afa8f777d463237dbc94f /src/content/components/common/mark.js | |
parent | f66e75575dd26b7f60e70c9856d8cd56770f74e7 (diff) |
Store local marks
Diffstat (limited to 'src/content/components/common/mark.js')
-rw-r--r-- | src/content/components/common/mark.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/content/components/common/mark.js b/src/content/components/common/mark.js new file mode 100644 index 0000000..06b2657 --- /dev/null +++ b/src/content/components/common/mark.js @@ -0,0 +1,59 @@ +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; +}; + +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 (key.shiftKey) { + consoleFrames.postError(window.document, 'Globa marks not supported'); + } 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); + } +} |