diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-06 22:17:01 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-06 22:17:18 +0900 |
commit | b002d70070a1b691b635220bc694c48df36faca5 (patch) | |
tree | fd69cc7a74e30c33f33376acf7e36ce585c819d9 /src/content/components/common/mark.ts | |
parent | a0882bbceb7ed71d56bf8557620449fbc3f19749 (diff) |
src/content
Diffstat (limited to 'src/content/components/common/mark.ts')
-rw-r--r-- | src/content/components/common/mark.ts | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/content/components/common/mark.ts b/src/content/components/common/mark.ts index 686116c..1237385 100644 --- a/src/content/components/common/mark.ts +++ b/src/content/components/common/mark.ts @@ -1,27 +1,30 @@ import * as markActions from '../../actions/mark'; import * as scrolls from '../..//scrolls'; import * as consoleFrames from '../..//console-frames'; +import * as keyUtils from '../../../shared/utils/keys'; +import Mark from '../../Mark'; -const cancelKey = (key): boolean => { - return key.key === 'Esc' || key.key === '[' && key.ctrlKey; +const cancelKey = (key: keyUtils.Key): boolean => { + return key.key === 'Esc' || key.key === '[' && Boolean(key.ctrlKey); }; -const globalKey = (key) => { +const globalKey = (key: string): boolean => { return (/^[A-Z0-9]$/).test(key); }; export default class MarkComponent { - constructor(body, store) { - this.body = body; + private store: any; + + constructor(store: any) { this.store = store; } // eslint-disable-next-line max-statements - key(key) { - let { mark: markStage, setting } = this.store.getState(); + key(key: keyUtils.Key) { + let { mark: markState, setting } = this.store.getState(); let smoothscroll = setting.properties.smoothscroll; - if (!markStage.setMode && !markStage.jumpMode) { + if (!markState.setMode && !markState.jumpMode) { return false; } @@ -32,26 +35,30 @@ export default class MarkComponent { if (key.ctrlKey || key.metaKey || key.altKey) { consoleFrames.postError('Unknown mark'); - } else if (globalKey(key.key) && markStage.setMode) { + } else if (globalKey(key.key) && markState.setMode) { this.doSetGlobal(key); - } else if (globalKey(key.key) && markStage.jumpMode) { + } else if (globalKey(key.key) && markState.jumpMode) { this.doJumpGlobal(key); - } else if (markStage.setMode) { + } else if (markState.setMode) { this.doSet(key); - } else if (markStage.jumpMode) { - this.doJump(markStage.marks, key, smoothscroll); + } else if (markState.jumpMode) { + this.doJump(markState.marks, key, smoothscroll); } this.store.dispatch(markActions.cancel()); return true; } - doSet(key) { + doSet(key: keyUtils.Key) { let { x, y } = scrolls.getScroll(); this.store.dispatch(markActions.setLocal(key.key, x, y)); } - doJump(marks, key, smoothscroll) { + doJump( + marks: { [key: string]: Mark }, + key: keyUtils.Key, + smoothscroll: boolean, + ) { if (!marks[key.key]) { consoleFrames.postError('Mark is not set'); return; @@ -61,12 +68,12 @@ export default class MarkComponent { scrolls.scrollTo(x, y, smoothscroll); } - doSetGlobal(key) { + doSetGlobal(key: keyUtils.Key) { let { x, y } = scrolls.getScroll(); this.store.dispatch(markActions.setGlobal(key.key, x, y)); } - doJumpGlobal(key) { + doJumpGlobal(key: keyUtils.Key) { this.store.dispatch(markActions.jumpGlobal(key.key)); } } |