add smoothscroll property
This commit is contained in:
parent
42839161bb
commit
2ca1b54faa
4 changed files with 36 additions and 23 deletions
|
@ -5,9 +5,12 @@ import * as navigates from 'content/navigates';
|
||||||
import * as urls from 'content/urls';
|
import * as urls from 'content/urls';
|
||||||
import * as consoleFrames from 'content/console-frames';
|
import * as consoleFrames from 'content/console-frames';
|
||||||
import * as addonActions from './addon';
|
import * as addonActions from './addon';
|
||||||
|
import * as properties from 'shared/settings/properties';
|
||||||
|
|
||||||
// eslint-disable-next-line complexity
|
// eslint-disable-next-line complexity
|
||||||
const exec = (operation) => {
|
const exec = (operation, settings) => {
|
||||||
|
let smoothscroll = settings.properties.smoothscroll ||
|
||||||
|
properties.defaults.smoothscroll;
|
||||||
switch (operation.type) {
|
switch (operation.type) {
|
||||||
case operations.ADDON_ENABLE:
|
case operations.ADDON_ENABLE:
|
||||||
return addonActions.enable();
|
return addonActions.enable();
|
||||||
|
@ -24,19 +27,19 @@ const exec = (operation) => {
|
||||||
type: messages.FIND_PREV,
|
type: messages.FIND_PREV,
|
||||||
}), '*');
|
}), '*');
|
||||||
case operations.SCROLL_VERTICALLY:
|
case operations.SCROLL_VERTICALLY:
|
||||||
return scrolls.scrollVertically(operation.count);
|
return scrolls.scrollVertically(operation.count, smoothscroll);
|
||||||
case operations.SCROLL_HORIZONALLY:
|
case operations.SCROLL_HORIZONALLY:
|
||||||
return scrolls.scrollHorizonally(operation.count);
|
return scrolls.scrollHorizonally(operation.count, smoothscroll);
|
||||||
case operations.SCROLL_PAGES:
|
case operations.SCROLL_PAGES:
|
||||||
return scrolls.scrollPages(operation.count);
|
return scrolls.scrollPages(operation.count, smoothscroll);
|
||||||
case operations.SCROLL_TOP:
|
case operations.SCROLL_TOP:
|
||||||
return scrolls.scrollTop();
|
return scrolls.scrollTop(smoothscroll);
|
||||||
case operations.SCROLL_BOTTOM:
|
case operations.SCROLL_BOTTOM:
|
||||||
return scrolls.scrollBottom();
|
return scrolls.scrollBottom(smoothscroll);
|
||||||
case operations.SCROLL_HOME:
|
case operations.SCROLL_HOME:
|
||||||
return scrolls.scrollHome();
|
return scrolls.scrollHome(smoothscroll);
|
||||||
case operations.SCROLL_END:
|
case operations.SCROLL_END:
|
||||||
return scrolls.scrollEnd();
|
return scrolls.scrollEnd(smoothscroll);
|
||||||
case operations.FOLLOW_START:
|
case operations.FOLLOW_START:
|
||||||
return window.top.postMessage(JSON.stringify({
|
return window.top.postMessage(JSON.stringify({
|
||||||
type: messages.FOLLOW_START,
|
type: messages.FOLLOW_START,
|
||||||
|
|
|
@ -47,7 +47,7 @@ export default class KeymapperComponent {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let operation = keymaps.get(matched[0]);
|
let operation = keymaps.get(matched[0]);
|
||||||
this.store.dispatch(operationActions.exec(operation));
|
this.store.dispatch(operationActions.exec(operation, state.setting));
|
||||||
this.store.dispatch(inputActions.clearKeys());
|
this.store.dispatch(inputActions.clearKeys());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,54 +108,62 @@ const roughScroll = (element, x, y) => {
|
||||||
element.scrollTo(x, y);
|
element.scrollTo(x, y);
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollVertically = (count) => {
|
const scroll = (element, x, y, smooth) => {
|
||||||
|
if (smooth) {
|
||||||
|
smoothScroll(element, x, y);
|
||||||
|
} else {
|
||||||
|
roughScroll(element, x, y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const scrollVertically = (count, smooth) => {
|
||||||
let target = scrollTarget();
|
let target = scrollTarget();
|
||||||
let x = target.scrollLeft;
|
let x = target.scrollLeft;
|
||||||
let y = target.scrollTop + SCROLL_DELTA_Y * count;
|
let y = target.scrollTop + SCROLL_DELTA_Y * count;
|
||||||
roughScroll(target, x, y);
|
scroll(target, x, y, smooth);
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollHorizonally = (count) => {
|
const scrollHorizonally = (count, smooth) => {
|
||||||
let target = scrollTarget();
|
let target = scrollTarget();
|
||||||
let x = target.scrollLeft + SCROLL_DELTA_X * count;
|
let x = target.scrollLeft + SCROLL_DELTA_X * count;
|
||||||
let y = target.scrollTop;
|
let y = target.scrollTop;
|
||||||
roughScroll(target, x, y);
|
scroll(target, x, y, smooth);
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollPages = (count) => {
|
const scrollPages = (count, smooth) => {
|
||||||
let target = scrollTarget();
|
let target = scrollTarget();
|
||||||
let height = target.clientHeight;
|
let height = target.clientHeight;
|
||||||
let x = target.scrollLeft;
|
let x = target.scrollLeft;
|
||||||
let y = target.scrollTop + height * count;
|
let y = target.scrollTop + height * count;
|
||||||
roughScroll(target, x, y);
|
scroll(target, x, y, smooth);
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollTop = () => {
|
const scrollTop = (smooth) => {
|
||||||
let target = scrollTarget();
|
let target = scrollTarget();
|
||||||
let x = target.scrollLeft;
|
let x = target.scrollLeft;
|
||||||
let y = 0;
|
let y = 0;
|
||||||
roughScroll(target, x, y);
|
scroll(target, x, y, smooth);
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollBottom = () => {
|
const scrollBottom = (smooth) => {
|
||||||
let target = scrollTarget();
|
let target = scrollTarget();
|
||||||
let x = target.scrollLeft;
|
let x = target.scrollLeft;
|
||||||
let y = target.scrollHeight;
|
let y = target.scrollHeight;
|
||||||
roughScroll(target, x, y);
|
scroll(target, x, y, smooth);
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollHome = () => {
|
const scrollHome = (smooth) => {
|
||||||
let target = scrollTarget();
|
let target = scrollTarget();
|
||||||
let x = 0;
|
let x = 0;
|
||||||
let y = target.scrollTop;
|
let y = target.scrollTop;
|
||||||
roughScroll(target, x, y);
|
scroll(target, x, y, smooth);
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollEnd = () => {
|
const scrollEnd = (smooth) => {
|
||||||
let target = scrollTarget();
|
let target = scrollTarget();
|
||||||
let x = target.scrollWidth;
|
let x = target.scrollWidth;
|
||||||
let y = target.scrollTop;
|
let y = target.scrollTop;
|
||||||
roughScroll(target, x, y);
|
scroll(target, x, y, smooth);
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -4,11 +4,13 @@
|
||||||
// mybool: 'boolean',
|
// mybool: 'boolean',
|
||||||
const types = {
|
const types = {
|
||||||
hintchars: 'string',
|
hintchars: 'string',
|
||||||
|
smoothscroll: 'boolean',
|
||||||
};
|
};
|
||||||
|
|
||||||
// describe default values of a property
|
// describe default values of a property
|
||||||
const defaults = {
|
const defaults = {
|
||||||
hintchars: 'abcdefghijklmnopqrstuvwxyz',
|
hintchars: 'abcdefghijklmnopqrstuvwxyz',
|
||||||
|
smoothscroll: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export { types, defaults };
|
export { types, defaults };
|
||||||
|
|
Reference in a new issue