diff options
Diffstat (limited to 'application')
-rw-r--r-- | application/components/keymap.vue | 22 | ||||
-rw-r--r-- | application/keymap.js | 45 |
2 files changed, 7 insertions, 60 deletions
diff --git a/application/components/keymap.vue b/application/components/keymap.vue index d10a2f0..c6e8a3f 100644 --- a/application/components/keymap.vue +++ b/application/components/keymap.vue @@ -68,9 +68,8 @@ export default { ) return ready ? this.keymap.layers.map((layer, i) => { - return layer.map((binding, j) => { - const parsed = parseKeyBinding(binding, this.sources) - return { layer: i, index: j, binding, parsed } + return layer.map((parsed, j) => { + return { layer: i, index: j, parsed } }) }) : [] } @@ -99,31 +98,24 @@ export default { const layer = this.parsedLayers.length const binding = '&trans' const makeKeycode = index => ({ - layer, index, binding, parsed: parseKeyBinding(binding, this.sources) + layer, index, binding, parsed: { value: binding, params: [] } }) const newLayer = times(this.layout.length, makeKeycode) const updatedLayerNames = [ ...this.keymap.layer_names, `Layer #${layer}` ] - const updatedLayers = [ ...this.parsedLayers, newLayer ] + const layers = [ ...this.parsedLayers, newLayer ] - this.$emit('update', { - ...this.keymap, - layer_names: updatedLayerNames, - layers: encode(updatedLayers) - }) + this.$emit('update', { ...this.keymap, layer_names: updatedLayerNames, layers }) }, handleUpdateLayer(layerIndex, updatedLayer) { const parsedLayers = this.parsedLayers.map(layer => map(layer, 'parsed')) - const updatedLayers = [ + const layers = [ ...parsedLayers.slice(0, layerIndex), updatedLayer, ...parsedLayers.slice(layerIndex + 1) ] - this.$emit('update', { - ...this.keymap, - layers: encode(updatedLayers) - }) + this.$emit('update', { ...this.keymap, layers }) } } } diff --git a/application/keymap.js b/application/keymap.js index bc1239d..124e37e 100644 --- a/application/keymap.js +++ b/application/keymap.js @@ -1,36 +1,7 @@ -import cloneDeep from 'lodash/cloneDeep' import get from 'lodash/get' import keyBy from 'lodash/keyBy' -import filter from 'lodash/filter' export { loadKeymap } from './api' -const paramsPattern = /\((.+)\)/ - -/** - * Parse a bind string into a tree of source values/parameters - * @param {String} binding - * @param {Map<code:obj>} sources - * @returns {Object} - */ -export function parseKeyBinding(binding, sources) { - function parse(code) { - const value = code.replace(paramsPattern, '') - const params = get(code.match(paramsPattern), '[1]', '').split(',') - .map(s => s.trim()) - .filter(s => s.length > 0) - .map(parse) - - return { value, params } - } - - const value = binding.match(/^(&.+?)\b/)[1] - const params = filter(binding.replace(/^&.+?\b\s*/, '') - .split(' ')) - .map(parse) - - return { value, params } -} - export function getBehaviourParams(parsed, behaviour) { const firstParsedParam = get(parsed, 'params[0]', {}) const commands = keyBy(behaviour.commands, 'code') @@ -41,19 +12,3 @@ export function getBehaviourParams(parsed, behaviour) { : [] ) } - -function encodeBindValue(parsed) { - const params = (parsed.params || []).map(encodeBindValue) - const paramString = params.length > 0 ? `(${params.join(',')})` : '' - return parsed.value + paramString -} - -function encodeKeyBinding(parsed) { - const { value, params } = parsed - - return `${value} ${params.map(encodeBindValue).join(' ')}`.trim() -} - -export function encode(parsedKeymap) { - return parsedKeymap.map(layer => layer.map(encodeKeyBinding)) -} |