(keyboardMap: keyboardKey[], text: string)
| 12 | * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key. |
| 13 | */ |
| 14 | export function parseKeyDef(keyboardMap: keyboardKey[], text: string) { |
| 15 | const defs: Array<{ |
| 16 | keyDef: keyboardKey |
| 17 | releasePrevious: boolean |
| 18 | releaseSelf: boolean |
| 19 | repeat: number |
| 20 | }> = [] |
| 21 | |
| 22 | do { |
| 23 | const { |
| 24 | type, |
| 25 | descriptor, |
| 26 | consumedLength, |
| 27 | releasePrevious, |
| 28 | releaseSelf = true, |
| 29 | repeat, |
| 30 | } = readNextDescriptor(text, 'keyboard') |
| 31 | |
| 32 | const keyDef = keyboardMap.find(def => { |
| 33 | if (type === '[') { |
| 34 | return def.code?.toLowerCase() === descriptor.toLowerCase() |
| 35 | } else if (type === '{') { |
| 36 | return def.key?.toLowerCase() === descriptor.toLowerCase() |
| 37 | } |
| 38 | return def.key === descriptor |
| 39 | }) ?? { |
| 40 | key: 'Unknown', |
| 41 | code: 'Unknown', |
| 42 | [type === '[' ? 'code' : 'key']: descriptor, |
| 43 | } |
| 44 | |
| 45 | defs.push({keyDef, releasePrevious, releaseSelf, repeat}) |
| 46 | |
| 47 | text = text.slice(consumedLength) |
| 48 | } while (text) |
| 49 | |
| 50 | return defs |
| 51 | } |
no test coverage detected