Skip to content

Commit

Permalink
Add randomness to typing speed
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricedb committed Dec 26, 2022
1 parent e692216 commit c4efbfb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Once Presentation Buddy is initialized and you have updated the instructions you
This extension contributes the following settings:

- `presentation-buddy.delay`: Delay (in ms) between keys entered. Defaults to 100ms.
- `presentation-buddy.randomness`: Randomness (in ms) between keys entered. Defaults to 25ms.

## Instructions

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
"default": 100,
"description": "Delay (in ms) between keys entered",
"scope": "user"
},
"presentation-buddy.randomness": {
"type": "integer",
"default": 25,
"description": "Randomness (in ms) between keys entered",
"scope": "user"
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/instruction-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
timeout,
getDelay,
readFileAsync,
getRandomness,
} from './utils';
import { setAwaiter } from './wait-for-input';

Expand Down Expand Up @@ -54,6 +55,8 @@ const typeTextIntoActiveTextEditor = async (
data: string[],
delay?: number
): Promise<void> => {
const delayBetweenChars = delay || getDelay();
const randomness = Math.min(delayBetweenChars, getRandomness());
const editor = window.activeTextEditor;
if (!editor) {
return;
Expand Down Expand Up @@ -83,7 +86,13 @@ const typeTextIntoActiveTextEditor = async (
});

char = data.shift();
delay === 0 ? void 0 : await timeout(delay || getDelay());

// give me a random number between -randomness and +randomness
const randomDelay =
delayBetweenChars +
(Math.floor(Math.random() * randomness * 2) - randomness);

delay === 0 ? void 0 : await timeout(randomDelay);
}
};

Expand Down
8 changes: 8 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ export function getDelay() {

return pause || 100;
}

export function getRandomness() {
const pause = workspace
.getConfiguration()
.get<number>('presentation-buddy.randomness');

return pause || 0;
}

0 comments on commit c4efbfb

Please sign in to comment.