parent
adc6a5175c
commit
879b5afe66
9 changed files with 134 additions and 126 deletions
@ -0,0 +1,15 @@ |
||||
import actions from '../actions'; |
||||
|
||||
export function keyPress(code, ctrl) { |
||||
return { |
||||
type: actions.INPUT_KEY_PRESS, |
||||
code, |
||||
ctrl |
||||
}; |
||||
} |
||||
|
||||
export function clearKeys() { |
||||
return { |
||||
type: actions.INPUT_CLEAR_KEYS |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
import actions from '../actions'; |
||||
|
||||
const defaultState = { |
||||
keys: [], |
||||
}; |
||||
|
||||
export default function reducer(state = defaultState, action = {}) { |
||||
switch (action.type) { |
||||
case actions.INPUT_KEY_PRESS: |
||||
return Object.assign({}, state, { |
||||
keys: state.keys.concat([{ |
||||
code: action.code, |
||||
ctrl: action.ctrl |
||||
}]) |
||||
}); |
||||
case actions.INPUT_CLEAR_KEYS: |
||||
return Object.assign({}, state, { |
||||
keys: [], |
||||
}); |
||||
default: |
||||
return state; |
||||
} |
||||
} |
@ -1,50 +0,0 @@ |
||||
import { expect } from "chai"; |
||||
import KeyQueue from '../../src/background/key-queue'; |
||||
|
||||
describe("keyQueue class", () => { |
||||
const KEYMAP = { |
||||
'g<C-X>GG': [], |
||||
'gg': [ 'scroll.top' ], |
||||
}; |
||||
|
||||
const g = 'g'.charCodeAt(0); |
||||
const G = 'G'.charCodeAt(0); |
||||
const x = 'x'.charCodeAt(0); |
||||
|
||||
describe("#push", () => { |
||||
it("returns matched action", () => { |
||||
let queue = new KeyQueue(KEYMAP); |
||||
queue.push({ code: g }); |
||||
let action = queue.push({ code: g }); |
||||
|
||||
expect(action).to.deep.equal([ 'scroll.top' ]); |
||||
}); |
||||
|
||||
it("returns null on no actions matched", () => { |
||||
let queue = new KeyQueue(KEYMAP); |
||||
queue.push({ code: g }); |
||||
let action = queue.push({ code: G }); |
||||
|
||||
expect(action).to.be.null; |
||||
expect(queue.asKeymapChars()).to.be.empty; |
||||
}); |
||||
}); |
||||
|
||||
describe('#asKeymapChars', () => { |
||||
let queue = new KeyQueue(KEYMAP); |
||||
queue.push({ code: g }); |
||||
queue.push({ code: x, ctrl: true }); |
||||
queue.push({ code: G }); |
||||
|
||||
expect(queue.asKeymapChars()).to.equal('g<C-X>G'); |
||||
}); |
||||
|
||||
describe('#asCaretChars', () => { |
||||
let queue = new KeyQueue(KEYMAP); |
||||
queue.push({ code: g }); |
||||
queue.push({ code: x, ctrl: true }); |
||||
queue.push({ code: G }); |
||||
|
||||
expect(queue.asCaretChars()).to.equal('g^XG'); |
||||
}); |
||||
}); |
@ -0,0 +1,31 @@ |
||||
import { expect } from "chai"; |
||||
import * as keys from '../../src/background/keys'; |
||||
|
||||
describe("keys", () => { |
||||
const KEYMAP = { |
||||
'g<C-X>GG': [], |
||||
'gg': { type: 'scroll.top' }, |
||||
}; |
||||
|
||||
const g = 'g'.charCodeAt(0); |
||||
const G = 'G'.charCodeAt(0); |
||||
const x = 'x'.charCodeAt(0); |
||||
|
||||
describe('#asKeymapChars', () => { |
||||
let keySequence = [ |
||||
{ code: g }, |
||||
{ code: x, ctrl: true }, |
||||
{ code: G } |
||||
]; |
||||
expect(keys.asKeymapChars(keySequence)).to.equal('g<C-X>G'); |
||||
}); |
||||
|
||||
describe('#asCaretChars', () => { |
||||
let keySequence = [ |
||||
{ code: g }, |
||||
{ code: x, ctrl: true }, |
||||
{ code: G } |
||||
]; |
||||
expect(keys.asCaretChars(keySequence)).to.equal('g^XG'); |
||||
}); |
||||
}); |
Reference in new issue