From b351dc5526d57dadf21e2a7f5868995bbbcdfd81 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 11 Sep 2019 16:33:22 -0700 Subject: [PATCH] fix --- lib/Input.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Input.js b/lib/Input.js index 5911afe3a0208..e7d36a8d89e64 100644 --- a/lib/Input.js +++ b/lib/Input.js @@ -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)); + } } } @@ -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); }