From 879b5afe66ee79424c3ffee3951ef1c0b8c86eaa Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 10 Sep 2017 21:28:00 +0900 Subject: key input sequence as action/reducer --- src/background/keys.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/background/keys.js (limited to 'src/background/keys.js') diff --git a/src/background/keys.js b/src/background/keys.js new file mode 100644 index 0000000..0ce53fa --- /dev/null +++ b/src/background/keys.js @@ -0,0 +1,57 @@ +import actions from '../actions'; + +const defaultKeymap = { + ':': { 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 }, + '': { type: actions.SCROLL_LINES, count: -1 }, + '': { type: actions.SCROLL_LINES, count: 1 }, + '': { type: actions.SCROLL_PAGES, count: -0.5 }, + '': { type: actions.SCROLL_PAGES, count: 0.5 }, + '': { type: actions.SCROLL_PAGES, count: -1 }, + '': { 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 }, +} + +const asKeymapChars = (keys) => { + return keys.map((k) => { + let c = String.fromCharCode(k.code); + if (k.ctrl) { + return ''; + } else { + return c + } + }).join(''); +} + +const asCaretChars = (keys) => { + return keys.map((k) => { + let c = String.fromCharCode(k.code); + if (k.ctrl) { + return '^' + c.toUpperCase(); + } else { + return c; + } + }).join(''); +} + +export { defaultKeymap, asKeymapChars, asCaretChars }; -- cgit v1.2.3