layerOfKey function
Handle?
layerOfKey(
- DraftDocument doc,
- SelectionKey key
Key key's layer as the picker shows it (spec 12b D12), or null for a
plain group or a key that no longer resolves:
- an instance's own layer;
- an ATTRIB's: its owning instance's;
- a parametric object's: its
objectLayer; - a drafted region's: its boundary's, whichever record was picked;
- any other root entity's: its own.
Implementation
Handle? layerOfKey(DraftDocument doc, SelectionKey key) {
final h = key.target;
final node = doc.tree[h];
if (node is InstanceNode) return node.layer;
if (node is GroupNode) {
return isParametricObject(doc, h) ? objectLayer(doc, h) : null;
}
if (node != null) return null;
final entities = doc.entities;
final slot = entities.slotOf(h);
if (slot == null) return null;
if (_owningInstance(doc, slot) case final owner?) return owner.layer;
final boundary = _boundaryOfFill(doc, slot);
return entities.layerAt(boundary == null ? slot : entities.slotOf(boundary)!);
}