( text: string, options: keyboardOptions, )
| 31 | * Modifiers like `{shift}` imply being kept pressed. This can be turned of per `{shift/}`. |
| 32 | */ |
| 33 | export 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 | |
| 75 | function readNextDescriptor(text: string) { |
| 76 | let pos = 0 |
no test coverage detected