Clear key actions without mutating the original layers (#340)
Fixes #339
This commit is contained in:
committed by
László Monda
parent
e713c52df8
commit
b51b9c9cb7
@@ -310,22 +310,45 @@ function generateMacroId(macros: Macro[]) {
|
|||||||
return newId + 1;
|
return newId + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkExistence(layers: Layer[], property: string, value: any) {
|
function checkExistence(layers: Layer[], property: string, value: any): Layer[] {
|
||||||
const newLayers = layers.map(layer => {
|
const keyActionsToClear: {
|
||||||
const newLayer = new Layer(layer);
|
layerIdx: number,
|
||||||
|
moduleIdx: number,
|
||||||
newLayer.modules = layer.modules.map((module: Module) => {
|
keyActionIdx: number
|
||||||
module.keyActions.forEach((action: KeyAction, index: number) => {
|
}[] = [];
|
||||||
|
for (let layerIdx = 0; layerIdx < layers.length; ++layerIdx) {
|
||||||
|
const modules = layers[layerIdx].modules;
|
||||||
|
for (let moduleIdx = 0; moduleIdx < modules.length; ++moduleIdx) {
|
||||||
|
const keyActions = modules[moduleIdx].keyActions;
|
||||||
|
for (let keyActionIdx = 0; keyActionIdx < keyActions.length; ++keyActionIdx) {
|
||||||
|
const action = keyActions[keyActionIdx];
|
||||||
if (action && action.hasOwnProperty(property) && action[property] === value) {
|
if (action && action.hasOwnProperty(property) && action[property] === value) {
|
||||||
module.keyActions[index] = undefined;
|
keyActionsToClear.push({
|
||||||
|
layerIdx,
|
||||||
|
moduleIdx,
|
||||||
|
keyActionIdx
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keyActionsToClear.length === 0) {
|
||||||
|
return layers;
|
||||||
|
}
|
||||||
|
|
||||||
return module;
|
const newLayers = [...layers];
|
||||||
});
|
for (const path of keyActionsToClear) {
|
||||||
|
if (newLayers[path.layerIdx] === layers[path.layerIdx]) {
|
||||||
return newLayer;
|
newLayers[path.layerIdx] = Object.assign(new Layer(), newLayers[path.layerIdx]);
|
||||||
});
|
newLayers[path.layerIdx].modules = [...newLayers[path.layerIdx].modules];
|
||||||
|
}
|
||||||
|
const newModules = newLayers[path.layerIdx].modules;
|
||||||
|
if (newModules[path.moduleIdx] === layers[path.layerIdx].modules[path.moduleIdx]) {
|
||||||
|
newModules[path.moduleIdx] = Object.assign(new Module(), newModules[path.moduleIdx]);
|
||||||
|
newModules[path.moduleIdx].keyActions = [...newModules[path.moduleIdx].keyActions];
|
||||||
|
}
|
||||||
|
newModules[path.moduleIdx].keyActions[path.keyActionIdx] = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return newLayers;
|
return newLayers;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user