src/content
This commit is contained in:
parent
a0882bbceb
commit
b002d70070
19 changed files with 119 additions and 80 deletions
6
src/content/Mark.ts
Normal file
6
src/content/Mark.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
export default interface Mark {
|
||||
x: number;
|
||||
y: number;
|
||||
// eslint-disable-next-line semi
|
||||
}
|
||||
|
|
@ -9,6 +9,20 @@ import * as messages from '../../shared/messages';
|
|||
import * as actions from './index';
|
||||
import * as consoleFrames from '../console-frames';
|
||||
|
||||
interface MyWindow extends Window {
|
||||
find(
|
||||
aString: string,
|
||||
aCaseSensitive?: boolean,
|
||||
aBackwards?: boolean,
|
||||
aWrapAround?: boolean,
|
||||
aWholeWord?: boolean,
|
||||
aSearchInFrames?: boolean,
|
||||
aShowDialog?: boolean): boolean;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-var, vars-on-top, init-declarations
|
||||
declare var window: MyWindow;
|
||||
|
||||
const find = (str: string, backwards: boolean): boolean => {
|
||||
let caseSensitive = false;
|
||||
let wrapScan = true;
|
||||
|
@ -18,7 +32,7 @@ const find = (str: string, backwards: boolean): boolean => {
|
|||
// because of same origin policy
|
||||
|
||||
// eslint-disable-next-line no-extra-parens
|
||||
let found = (<any>window).find(str, caseSensitive, backwards, wrapScan);
|
||||
let found = window.find(str, caseSensitive, backwards, wrapScan);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
|
@ -28,7 +42,7 @@ const find = (str: string, backwards: boolean): boolean => {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line no-extra-parens
|
||||
return (<any>window).find(str, caseSensitive, backwards, wrapScan);
|
||||
return window.find(str, caseSensitive, backwards, wrapScan);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line max-statements
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import Redux from 'redux';
|
||||
import Settings from '../../shared/Settings';
|
||||
import * as keyUtils from '../../shared/utils/keys';
|
||||
|
||||
// Enable/disable
|
||||
export const ADDON_SET_ENABLED = 'addon.set.enabled';
|
||||
|
@ -51,7 +52,7 @@ export interface SettingSetAction extends Redux.Action {
|
|||
|
||||
export interface InputKeyPressAction extends Redux.Action {
|
||||
type: typeof INPUT_KEY_PRESS;
|
||||
key: string;
|
||||
key: keyUtils.Key;
|
||||
}
|
||||
|
||||
export interface InputClearKeysAction extends Redux.Action {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as actions from './index';
|
||||
import * as keyUtils from '../../shared/utils/keys';
|
||||
|
||||
const keyPress = (key: string): actions.InputAction => {
|
||||
const keyPress = (key: keyUtils.Key): actions.InputAction => {
|
||||
return {
|
||||
type: actions.INPUT_KEY_PRESS,
|
||||
key,
|
||||
|
|
|
@ -18,7 +18,7 @@ export default class Common {
|
|||
constructor(win: Window, store: any) {
|
||||
const input = new InputComponent(win.document.body);
|
||||
const follow = new FollowComponent(win);
|
||||
const mark = new MarkComponent(win.document.body, store);
|
||||
const mark = new MarkComponent(store);
|
||||
const keymapper = new KeymapperComponent(store);
|
||||
|
||||
input.onKey((key: keys.Key) => follow.key(key));
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,5 +12,5 @@ if (window.self === window.top) {
|
|||
}
|
||||
|
||||
let style = window.document.createElement('style');
|
||||
style.textContent = consoleFrameStyle.default;
|
||||
style.textContent = consoleFrameStyle;
|
||||
window.document.head.appendChild(style);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import * as actions from '../actions';
|
||||
import * as keyUtils from '../../shared/utils/keys';
|
||||
|
||||
export interface State {
|
||||
keys: string[];
|
||||
keys: keyUtils.Key[],
|
||||
}
|
||||
|
||||
const defaultState: State = {
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import Mark from '../Mark';
|
||||
import * as actions from '../actions';
|
||||
|
||||
interface Mark {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
export interface State {
|
||||
setMode: boolean;
|
||||
jumpMode: boolean;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
exports.default = `
|
||||
export default `
|
||||
.vimvixen-console-frame {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
|
Reference in a new issue