diff options
author | Nick Coutsos <[email protected]> | 2021-12-07 20:38:53 -0500 |
---|---|---|
committer | Nick Coutsos <[email protected]> | 2021-12-07 20:38:53 -0500 |
commit | 7add48d77e64a1eadc7a0f0538faf39d1ae4c192 (patch) | |
tree | 5e7d43e0d8e0e0912e205725e6d9a65f3961a94a | |
parent | 2eaabf8eeb52a049a721bb96bd3d29e5c5040a8e (diff) | |
download | keymap-editor-7add48d77e64a1eadc7a0f0538faf39d1ae4c192.tar.gz keymap-editor-7add48d77e64a1eadc7a0f0538faf39d1ae4c192.zip |
Fix index error when rendering keymap with too many keys
-rw-r--r-- | api/services/zmk/layout.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/api/services/zmk/layout.js b/api/services/zmk/layout.js index 383e710..c914177 100644 --- a/api/services/zmk/layout.js +++ b/api/services/zmk/layout.js @@ -16,9 +16,16 @@ function renderTable (layout, layer, opts={}) { } = opts const minWidth = useQuotes ? 9 : 7 const table = layer.reduce((map, code, i) => { - const { row = 0, col } = layout[i] - map[row] = map[row] || [] - map[row][col || map[row].length] = code + // TODO: this would be better as a loop over `layout`, checking for a + // matching element in the `layer` array. Or, alternatively, an earlier + // validation that asserts each layer is equal in length to the number of + // keys in the layout. + if (layout[i]) { + const { row = 0, col } = layout[i] + map[row] = map[row] || [] + map[row][col || map[row].length] = code + } + return map }, []) |