Skip to content

Commit

Permalink
fix: special handling for Enter press in textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
aldeed committed Jul 6, 2020
1 parent 9795965 commit 5933874
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/build-workflow/buildPressSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ const debug = Debug('qawolf:buildPressSteps');
* navigation purposes on any website.
*/
const KEYS_TO_TRACK_ALWAYS = new Set([
'Enter',
'Escape',
'Tab'
]);

/**
* A subset of the full list:
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
*
* These are key presses that we want to include when playing back as long as they
* aren't being pressed as part of editing in a textarea.
*/
const KEYS_TO_TRACK_FOR_NON_TEXTAREA = new Set([
'Enter'
]);

/**
* A subset of the full list:
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
Expand Down Expand Up @@ -53,6 +63,7 @@ const KEYS_TO_TRACK_FOR_NON_INPUT = new Set([
*/
const shouldTrackKeyPress = (key: string, target: Doc): boolean => {
if (KEYS_TO_TRACK_ALWAYS.has(key)) return true;
if (!isTextareaTarget(target) && KEYS_TO_TRACK_FOR_NON_TEXTAREA.has(key)) return true;
if (!isInputTarget(target) && !isTextareaTarget(target) && KEYS_TO_TRACK_FOR_NON_INPUT.has(key)) return true;
return false;
}
Expand Down

0 comments on commit 5933874

Please sign in to comment.