|
|
@ -1,27 +1,30 @@ |
|
|
|
import * as markActions from '../../actions/mark'; |
|
|
|
import * as markActions from '../../actions/mark'; |
|
|
|
import * as scrolls from '../..//scrolls'; |
|
|
|
import * as scrolls from '../..//scrolls'; |
|
|
|
import * as consoleFrames from '../..//console-frames'; |
|
|
|
import * as consoleFrames from '../..//console-frames'; |
|
|
|
|
|
|
|
import * as keyUtils from '../../../shared/utils/keys'; |
|
|
|
|
|
|
|
import Mark from '../../Mark'; |
|
|
|
|
|
|
|
|
|
|
|
const cancelKey = (key): boolean => { |
|
|
|
const cancelKey = (key: keyUtils.Key): boolean => { |
|
|
|
return key.key === 'Esc' || key.key === '[' && key.ctrlKey; |
|
|
|
return key.key === 'Esc' || key.key === '[' && Boolean(key.ctrlKey); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const globalKey = (key) => { |
|
|
|
const globalKey = (key: string): boolean => { |
|
|
|
return (/^[A-Z0-9]$/).test(key); |
|
|
|
return (/^[A-Z0-9]$/).test(key); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default class MarkComponent { |
|
|
|
export default class MarkComponent { |
|
|
|
constructor(body, store) { |
|
|
|
private store: any; |
|
|
|
this.body = body; |
|
|
|
|
|
|
|
|
|
|
|
constructor(store: any) { |
|
|
|
this.store = store; |
|
|
|
this.store = store; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line max-statements
|
|
|
|
// eslint-disable-next-line max-statements
|
|
|
|
key(key) { |
|
|
|
key(key: keyUtils.Key) { |
|
|
|
let { mark: markStage, setting } = this.store.getState(); |
|
|
|
let { mark: markState, setting } = this.store.getState(); |
|
|
|
let smoothscroll = setting.properties.smoothscroll; |
|
|
|
let smoothscroll = setting.properties.smoothscroll; |
|
|
|
|
|
|
|
|
|
|
|
if (!markStage.setMode && !markStage.jumpMode) { |
|
|
|
if (!markState.setMode && !markState.jumpMode) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -32,26 +35,30 @@ export default class MarkComponent { |
|
|
|
|
|
|
|
|
|
|
|
if (key.ctrlKey || key.metaKey || key.altKey) { |
|
|
|
if (key.ctrlKey || key.metaKey || key.altKey) { |
|
|
|
consoleFrames.postError('Unknown mark'); |
|
|
|
consoleFrames.postError('Unknown mark'); |
|
|
|
} else if (globalKey(key.key) && markStage.setMode) { |
|
|
|
} else if (globalKey(key.key) && markState.setMode) { |
|
|
|
this.doSetGlobal(key); |
|
|
|
this.doSetGlobal(key); |
|
|
|
} else if (globalKey(key.key) && markStage.jumpMode) { |
|
|
|
} else if (globalKey(key.key) && markState.jumpMode) { |
|
|
|
this.doJumpGlobal(key); |
|
|
|
this.doJumpGlobal(key); |
|
|
|
} else if (markStage.setMode) { |
|
|
|
} else if (markState.setMode) { |
|
|
|
this.doSet(key); |
|
|
|
this.doSet(key); |
|
|
|
} else if (markStage.jumpMode) { |
|
|
|
} else if (markState.jumpMode) { |
|
|
|
this.doJump(markStage.marks, key, smoothscroll); |
|
|
|
this.doJump(markState.marks, key, smoothscroll); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.store.dispatch(markActions.cancel()); |
|
|
|
this.store.dispatch(markActions.cancel()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
doSet(key) { |
|
|
|
doSet(key: keyUtils.Key) { |
|
|
|
let { x, y } = scrolls.getScroll(); |
|
|
|
let { x, y } = scrolls.getScroll(); |
|
|
|
this.store.dispatch(markActions.setLocal(key.key, x, y)); |
|
|
|
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]) { |
|
|
|
if (!marks[key.key]) { |
|
|
|
consoleFrames.postError('Mark is not set'); |
|
|
|
consoleFrames.postError('Mark is not set'); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -61,12 +68,12 @@ export default class MarkComponent { |
|
|
|
scrolls.scrollTo(x, y, smoothscroll); |
|
|
|
scrolls.scrollTo(x, y, smoothscroll); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
doSetGlobal(key) { |
|
|
|
doSetGlobal(key: keyUtils.Key) { |
|
|
|
let { x, y } = scrolls.getScroll(); |
|
|
|
let { x, y } = scrolls.getScroll(); |
|
|
|
this.store.dispatch(markActions.setGlobal(key.key, x, y)); |
|
|
|
this.store.dispatch(markActions.setGlobal(key.key, x, y)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
doJumpGlobal(key) { |
|
|
|
doJumpGlobal(key: keyUtils.Key) { |
|
|
|
this.store.dispatch(markActions.jumpGlobal(key.key)); |
|
|
|
this.store.dispatch(markActions.jumpGlobal(key.key)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|