Store local marks

jh-changes
Shin'ya Ueoka 6 years ago
parent f66e75575d
commit 6e6e306275
  1. 8
      src/content/actions/operation.js
  2. 7
      src/content/components/common/index.js
  3. 59
      src/content/components/common/mark.js
  4. 3
      src/content/reducers/index.js
  5. 30
      src/content/scrolls.js

@ -40,16 +40,16 @@ const exec = (operation, repeat, settings, addonEnabled) => {
scrolls.scrollPages(operation.count, smoothscroll, repeat); scrolls.scrollPages(operation.count, smoothscroll, repeat);
break; break;
case operations.SCROLL_TOP: case operations.SCROLL_TOP:
scrolls.scrollTop(smoothscroll, repeat); scrolls.scrollToTop(smoothscroll);
break; break;
case operations.SCROLL_BOTTOM: case operations.SCROLL_BOTTOM:
scrolls.scrollBottom(smoothscroll, repeat); scrolls.scrollToBottom(smoothscroll);
break; break;
case operations.SCROLL_HOME: case operations.SCROLL_HOME:
scrolls.scrollHome(smoothscroll, repeat); scrolls.scrollToHome(smoothscroll);
break; break;
case operations.SCROLL_END: case operations.SCROLL_END:
scrolls.scrollEnd(smoothscroll, repeat); scrolls.scrollToEnd(smoothscroll);
break; break;
case operations.FOLLOW_START: case operations.FOLLOW_START:
window.top.postMessage(JSON.stringify({ window.top.postMessage(JSON.stringify({

@ -1,6 +1,7 @@
import InputComponent from './input'; import InputComponent from './input';
import KeymapperComponent from './keymapper';
import FollowComponent from './follow'; import FollowComponent from './follow';
import MarkComponent from './mark';
import KeymapperComponent from './keymapper';
import * as settingActions from 'content/actions/setting'; import * as settingActions from 'content/actions/setting';
import messages from 'shared/messages'; import messages from 'shared/messages';
import * as addonActions from '../../actions/addon'; import * as addonActions from '../../actions/addon';
@ -8,11 +9,13 @@ import * as blacklists from 'shared/blacklists';
export default class Common { export default class Common {
constructor(win, store) { constructor(win, store) {
const follow = new FollowComponent(win, store);
const input = new InputComponent(win.document.body, 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); const keymapper = new KeymapperComponent(store);
input.onKey(key => follow.key(key)); input.onKey(key => follow.key(key));
input.onKey(key => mark.key(key));
input.onKey(key => keymapper.key(key)); input.onKey(key => keymapper.key(key));
this.win = win; this.win = win;

@ -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);
}
}

@ -4,7 +4,8 @@ import find from './find';
import setting from './setting'; import setting from './setting';
import input from './input'; import input from './input';
import followController from './follow-controller'; import followController from './follow-controller';
import mark from './mark';
export default combineReducers({ export default combineReducers({
addon, find, setting, input, followController, addon, find, setting, input, followController, mark,
}); });

@ -130,6 +130,11 @@ const scroller = (element, smooth, repeat) => {
return new RoughtScroller(element); return new RoughtScroller(element);
}; };
const getScroll = () => {
let target = scrollTarget();
return { x: target.scrollLeft, y: target.scrollTop };
};
const scrollVertically = (count, smooth, repeat) => { const scrollVertically = (count, smooth, repeat) => {
let target = scrollTarget(); let target = scrollTarget();
let x = target.scrollLeft; let x = target.scrollLeft;
@ -158,35 +163,42 @@ const scrollPages = (count, smooth, repeat) => {
scroller(target, smooth, repeat).scroll(x, y); scroller(target, smooth, repeat).scroll(x, y);
}; };
const scrollTop = (smooth, repeat) => { const scrollTo = (x, y, smooth) => {
let target = scrollTarget();
scroller(target, smooth, false).scroll(x, y);
};
const scrollToTop = (smooth) => {
let target = scrollTarget(); let target = scrollTarget();
let x = target.scrollLeft; let x = target.scrollLeft;
let y = 0; let y = 0;
scroller(target, smooth, repeat).scroll(x, y); scroller(target, smooth, false).scroll(x, y);
}; };
const scrollBottom = (smooth, repeat) => { const scrollToBottom = (smooth) => {
let target = scrollTarget(); let target = scrollTarget();
let x = target.scrollLeft; let x = target.scrollLeft;
let y = target.scrollHeight; let y = target.scrollHeight;
scroller(target, smooth, repeat).scroll(x, y); scroller(target, smooth, false).scroll(x, y);
}; };
const scrollHome = (smooth, repeat) => { const scrollToHome = (smooth) => {
let target = scrollTarget(); let target = scrollTarget();
let x = 0; let x = 0;
let y = target.scrollTop; let y = target.scrollTop;
scroller(target, smooth, repeat).scroll(x, y); scroller(target, smooth, false).scroll(x, y);
}; };
const scrollEnd = (smooth, repeat) => { const scrollToEnd = (smooth) => {
let target = scrollTarget(); let target = scrollTarget();
let x = target.scrollWidth; let x = target.scrollWidth;
let y = target.scrollTop; let y = target.scrollTop;
scroller(target, smooth, repeat).scroll(x, y); scroller(target, smooth, false).scroll(x, y);
}; };
export { export {
getScroll,
scrollVertically, scrollHorizonally, scrollPages, scrollVertically, scrollHorizonally, scrollPages,
scrollTop, scrollBottom, scrollHome, scrollEnd scrollTo,
scrollToTop, scrollToBottom, scrollToHome, scrollToEnd
}; };