Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: avoid unnecessary zero-delays in input code #4934

Merged
merged 1 commit into from Oct 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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