diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-10 21:28:00 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-10 22:14:55 +0900 |
commit | 879b5afe66ee79424c3ffee3951ef1c0b8c86eaa (patch) | |
tree | 0306dfc26a4312f14084e295deefdf235abad34f /src/background/key-queue.js | |
parent | adc6a5175c0d8b83e45b9e8d99109c1605ad29ac (diff) |
key input sequence as action/reducer
Diffstat (limited to 'src/background/key-queue.js')
-rw-r--r-- | src/background/key-queue.js | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/src/background/key-queue.js b/src/background/key-queue.js deleted file mode 100644 index 924bf77..0000000 --- a/src/background/key-queue.js +++ /dev/null @@ -1,82 +0,0 @@ -import actions from '../actions'; - -const DEFAULT_KEYMAP = { - ':': { type: actions.CMD_OPEN }, - 'o': { type: actions.CMD_TABS_OPEN, alter: false }, - 'O': { type: actions.CMD_TABS_OPEN, alter: true }, - 'b': { type: actions.CMD_BUFFER }, - 'k': { type: actions.SCROLL_LINES, count: -1 }, - 'j': { type: actions.SCROLL_LINES, count: 1 }, - '<C-E>': { type: actions.SCROLL_LINES, count: -1 }, - '<C-Y>': { type: actions.SCROLL_LINES, count: 1 }, - '<C-U>': { type: actions.SCROLL_PAGES, count: -0.5 }, - '<C-D>': { type: actions.SCROLL_PAGES, count: 0.5 }, - '<C-B>': { type: actions.SCROLL_PAGES, count: -1 }, - '<C-F>': { type: actions.SCROLL_PAGES, count: 1 }, - 'gg': { type: actions.SCROLL_TOP }, - 'G': { type: actions.SCROLL_BOTTOM }, - '0': { type: actions.SCROLL_LEFT }, - '$': { type: actions.SCROLL_RIGHT }, - 'd': { type: actions.TABS_CLOSE }, - 'u': { type: actions.TABS_REOPEN }, - 'h': { type: actions.TABS_PREV, count: 1 }, - 'l': { type: actions.TABS_NEXT, count: 1 }, - 'r': { type: actions.TABS_RELOAD, cache: false }, - 'R': { type: actions.TABS_RELOAD, cache: true }, - 'zi': { type: actions.ZOOM_IN }, - 'zo': { type: actions.ZOOM_OUT }, - 'zz': { type: actions.ZOOM_NEUTRAL }, - 'f': { type: actions.FOLLOW_START, newTab: false }, - 'F': { type: actions.FOLLOW_START, newTab: true }, - 'H': { type: actions.HISTORY_PREV }, - 'L': { type: actions.HISTORY_NEXT }, -} - -export default class KeyQueue { - - constructor(keymap = DEFAULT_KEYMAP) { - this.data = []; - this.keymap = keymap; - } - - push(key) { - this.data.push(key); - - let current = this.asKeymapChars(); - let filtered = Object.keys(this.keymap).filter((keys) => { - return keys.startsWith(current); - }); - - if (filtered.length == 0) { - this.data = []; - return null; - } else if (filtered.length === 1 && current === filtered[0]) { - let action = this.keymap[filtered[0]]; - this.data = []; - return action; - } - return null; - } - - asKeymapChars() { - return this.data.map((k) => { - let c = String.fromCharCode(k.code); - if (k.ctrl) { - return '<C-' + c.toUpperCase() + '>'; - } else { - return c - } - }).join(''); - } - - asCaretChars() { - return this.data.map((k) => { - let c = String.fromCharCode(k.code); - if (k.ctrl) { - return '^' + c.toUpperCase(); - } else { - return c; - } - }).join(''); - } -} |