Skip to content

Commit

Permalink
Tweak getSearchTargets
Browse files Browse the repository at this point in the history
  • Loading branch information
nickcoutsos committed May 1, 2022
1 parent c752f5d commit 2aacaa0
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions app/src/Keyboard/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ function Keyboard(props) {
)
}, [keycodes, behaviours, keymap])

const searchTargets = useMemo(() => {
return {
behaviour: behaviours,
layer: availableLayers,
mod: filter(keycodes, 'isModifier'),
code: keycodes
}
}, [behaviours, keycodes, availableLayers])

const getSearchTargets = useMemo(() => function (param, behaviour) {
// Special case for behaviour commands which can dynamically add another
// parameter that isn't defined at the root level of the behaviour.
Expand All @@ -48,20 +57,16 @@ function Keyboard(props) {
return param.enum.map(v => ({ code: v }))
}

switch (param) {
case 'behaviour':
return behaviours
case 'layer':
return availableLayers
case 'mod':
return filter(keycodes, 'isModifier')
case 'command':
return get(sources, ['behaviours', behaviour, 'commands'], [])
case 'kc':
default:
return keycodes
if (param === 'command') {
return get(sources, ['behaviours', behaviour, 'commands'], [])
}
}, [keycodes, behaviours, sources, availableLayers])

if (!searchTargets[param]) {
console.log('cannot find target for', param)
}

return searchTargets[param]
}, [searchTargets, sources])

const boundingBox = useMemo(() => function () {
return layout.map(key => getKeyBoundingBox(
Expand Down

0 comments on commit 2aacaa0

Please sign in to comment.