feat(keyboard): make keyboard.down generate input event by default (#1016)

This patch starts generating input events for `keyboard.down`, addressing bullet 2 of
#723. With this patch, there's no longer any difference between `keboard.press('a')` and
`keyboard.press('a', {text: 'a'})`.

BREAKING CHANGE:
`keyboard.down('a')` starts generating input event (wasn't the case before).

References #723
This commit is contained in:
JoelEinbinder
2017-10-13 15:22:55 -07:00
committed by Andrey Lushnikov
parent a02347e3ef
commit 6a8865cd85
3 changed files with 12 additions and 4 deletions

View File

@@ -30,8 +30,11 @@ class Keyboard {
* @param {string} key
* @param {{text: string}=} options
*/
async down(key, options = {text: ''}) {
const {text} = options;
async down(key, options = {text: undefined}) {
let { text } = options;
// If the key is a single character, and no modifiers are pressed except shift, a keypress should be generated by default.
if (text === undefined)
text = (key.length === 1 && !(this._modifiers & ~8)) ? key : '';
const autoRepeat = this._pressedKeys.has(key);
this._pressedKeys.add(key);
this._modifiers |= this._modifierBit(key);