diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-12-22 10:47:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-22 10:47:00 +0900 |
commit | b2dcdedad729ff7087867da50e20578f9fc8fb29 (patch) | |
tree | 033ecffbd7db9b6db8000464a68d748fcae1dc3d /src/shared | |
parent | 3c7230c3036e8bb2b2e9a752be9b0ef4a0a7349d (diff) | |
parent | 75f86907fc2699c0f0661d4780c38249a18f849b (diff) |
Merge pull request #689 from ueokande/n-times-repeat-operations
Repeat commands n-times
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/messages.ts | 1 | ||||
-rw-r--r-- | src/shared/operations.ts | 26 | ||||
-rw-r--r-- | src/shared/settings/Key.ts | 22 | ||||
-rw-r--r-- | src/shared/settings/KeySequence.ts | 54 |
4 files changed, 44 insertions, 59 deletions
diff --git a/src/shared/messages.ts b/src/shared/messages.ts index 36a23d8..7f8bd5b 100644 --- a/src/shared/messages.ts +++ b/src/shared/messages.ts @@ -49,6 +49,7 @@ export const NAVIGATE_LINK_PREV = 'navigate.link.prev'; export interface BackgroundOperationMessage { type: typeof BACKGROUND_OPERATION; + repeat: number; operation: operations.Operation; } diff --git a/src/shared/operations.ts b/src/shared/operations.ts index 1ce5256..67c5ca8 100644 --- a/src/shared/operations.ts +++ b/src/shared/operations.ts @@ -508,3 +508,29 @@ export const valueOf = (o: any): Operation => { } throw new TypeError('Unknown operation type: ' + o.type); }; + +export const isNRepeatable = (type: string): boolean => { + switch (type) { + case SCROLL_VERTICALLY: + case SCROLL_HORIZONALLY: + case SCROLL_PAGES: + case NAVIGATE_HISTORY_PREV: + case NAVIGATE_HISTORY_NEXT: + case NAVIGATE_PARENT: + case TAB_CLOSE: + case TAB_CLOSE_FORCE: + case TAB_CLOSE_RIGHT: + case TAB_REOPEN: + case TAB_PREV: + case TAB_NEXT: + case TAB_DUPLICATE: + case ZOOM_IN: + case ZOOM_OUT: + case URLS_PASTE: + case FIND_NEXT: + case FIND_PREV: + case REPEAT_LAST: + return true; + } + return false; +}; diff --git a/src/shared/settings/Key.ts b/src/shared/settings/Key.ts index b11eeb2..3a3eb3b 100644 --- a/src/shared/settings/Key.ts +++ b/src/shared/settings/Key.ts @@ -1,3 +1,5 @@ +const digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; + export default class Key { public readonly key: string; @@ -9,12 +11,18 @@ export default class Key { public readonly meta: boolean; - constructor({ key, shift, ctrl, alt, meta }: { + constructor({ + key, + shift = false, + ctrl = false, + alt = false, + meta = false, + }: { key: string; - shift: boolean; - ctrl: boolean; - alt: boolean; - meta: boolean; + shift?: boolean; + ctrl?: boolean; + alt?: boolean; + meta?: boolean; }) { this.key = key; this.shift = shift; @@ -51,6 +59,10 @@ export default class Key { }); } + isDigit(): boolean { + return digits.includes(this.key); + } + equals(key: Key) { return this.key === key.key && this.ctrl === key.ctrl && diff --git a/src/shared/settings/KeySequence.ts b/src/shared/settings/KeySequence.ts deleted file mode 100644 index abae61a..0000000 --- a/src/shared/settings/KeySequence.ts +++ /dev/null @@ -1,54 +0,0 @@ -import Key from './Key'; - -export default class KeySequence { - constructor( - public readonly keys: Key[], - ) { - } - - push(key: Key): number { - return this.keys.push(key); - } - - length(): number { - return this.keys.length; - } - - startsWith(o: KeySequence): boolean { - if (this.keys.length < o.keys.length) { - return false; - } - for (let i = 0; i < o.keys.length; ++i) { - if (!this.keys[i].equals(o.keys[i])) { - return false; - } - } - return true; - } - - static fromMapKeys(keys: string): KeySequence { - const fromMapKeysRecursive = ( - remaining: string, mappedKeys: Key[], - ): Key[] => { - if (remaining.length === 0) { - return mappedKeys; - } - - let nextPos = 1; - if (remaining.startsWith('<')) { - let ltPos = remaining.indexOf('>'); - if (ltPos > 0) { - nextPos = ltPos + 1; - } - } - - return fromMapKeysRecursive( - remaining.slice(nextPos), - mappedKeys.concat([Key.fromMapKey(remaining.slice(0, nextPos))]) - ); - }; - - let data = fromMapKeysRecursive(keys, []); - return new KeySequence(data); - } -} |