Allow quick access by layer id

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2023-01-20 21:09:20 -03:00
parent fa82cfd35d
commit b1c52a859e
3 changed files with 5 additions and 3 deletions

View file

@ -355,7 +355,7 @@
src="js/lib/workspaces.js?v=4fbd55b"
type="text/javascript"></script>
<script src="js/lib/input.js?v=aa14afc" type="text/javascript"></script>
<script src="js/lib/layers.js?v=a1f8aea" type="text/javascript"></script>
<script src="js/lib/layers.js?v=b5f7b59" type="text/javascript"></script>
<script src="js/lib/commands.js?v=bf23c83" type="text/javascript"></script>
<script src="js/lib/toolbar.js?v=306d637" type="text/javascript"></script>

View file

@ -38,7 +38,7 @@
* @property {Point} inputOffset The offset for calculating layer coordinates from input element input information
* @property {Point} origin The location of the origin ((0, 0) point) of the collection (If canvas goes from -64, -32 to 128, 512, it's (64, 32))
* @property {BoundingBox} bb The current bounding box of the collection, in layer coordinates
* @property {{[key: string]: Layer}} layers An object for quick access to named layers of the collection
* @property {{[key: string]: Layer}} layers An object for quick access to layers of the collection
* @property {Size} size The size of the collection (CSS)
* @property {Size} resolution The resolution of the collection (canvas)
* @property {function} expand Expands the collection and its full layers by the specified amounts

View file

@ -618,6 +618,7 @@ const layers = {
collection._layers.splice(index, 0, layer);
}
if (key) collection.layers[key] = layer;
collection.layers[id] = layer;
if (key === null)
console.debug(
@ -651,7 +652,8 @@ const layers = {
layers.listen.onlayerdelete.emit({
layer: lobj,
});
if (lobj.key) delete collection.layers[lobj.key];
if (lobj.key) collection.layers[lobj.key] = undefined;
collection.layers[lobj.id] = undefined;
collection.element.removeChild(lobj.canvas);