Skip to content

Commit

Permalink
fix: avoid unnecessary zero-delays in input code (#4934)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored and mathiasbynens committed Oct 21, 2019
1 parent 11ff374 commit 3773229
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/Input.js
Expand Up @@ -156,16 +156,15 @@ class Keyboard {
* @param {{delay: (number|undefined)}=} options
*/
async type(text, options) {
let delay = 0;
if (options && options.delay)
delay = options.delay;
const delay = (options && options.delay) || null;
for (const char of text) {
if (keyDefinitions[char])
if (keyDefinitions[char]) {
await this.press(char, {delay});
else
} else {
if (delay)
await new Promise(f => setTimeout(f, delay));
await this.sendCharacter(char);
if (delay)
await new Promise(f => setTimeout(f, delay));
}
}
}

Expand All @@ -176,7 +175,7 @@ class Keyboard {
async press(key, options = {}) {
const {delay = null} = options;
await this.down(key, options);
if (delay !== null)
if (delay)
await new Promise(f => setTimeout(f, options.delay));
await this.up(key);
}
Expand Down

0 comments on commit 3773229

Please sign in to comment.