MCPcopy Create free account
hub / github.com/testing-library/user-event / getNextKeyDef

Function getNextKeyDef

src/keyboard/getNextKeyDef.ts:33–73  ·  view source on GitHub ↗
(
  text: string,
  options: keyboardOptions,
)

Source from the content-addressed store, hash-verified

31 * Modifiers like `{shift}` imply being kept pressed. This can be turned of per `{shift/}`.
32 */
33export function getNextKeyDef(
34 text: string,
35 options: keyboardOptions,
36): {
37 keyDef: keyboardKey
38 consumedLength: number
39 releasePrevious: boolean
40 releaseSelf: boolean
41 repeat: number
42} {
43 const {
44 type,
45 descriptor,
46 consumedLength,
47 releasePrevious,
48 releaseSelf,
49 repeat,
50 } = readNextDescriptor(text)
51
52 const keyDef = options.keyboardMap.find(def => {
53 if (type === '[') {
54 return def.code?.toLowerCase() === descriptor.toLowerCase()
55 } else if (type === '{') {
56 const key = mapLegacyKey(descriptor)
57 return def.key?.toLowerCase() === key.toLowerCase()
58 }
59 return def.key === descriptor
60 }) ?? {
61 key: 'Unknown',
62 code: 'Unknown',
63 [type === '[' ? 'code' : 'key']: descriptor,
64 }
65
66 return {
67 keyDef,
68 consumedLength,
69 releasePrevious,
70 releaseSelf,
71 repeat,
72 }
73}
74
75function readNextDescriptor(text: string) {
76 let pos = 0

Callers 2

getNextKeyDef.tsFile · 0.90
keyboardImplementationFunction · 0.90

Calls 2

readNextDescriptorFunction · 0.85
mapLegacyKeyFunction · 0.85

Tested by

no test coverage detected