We need a better mechanism for managing annotation active states (currently implemented as a volatile active property on annotations)
The current approach is pretty perfect for highlighting nodes that are displayed somewhere in a container and are already rendered in one or more places. using anno.setActive(true) we incrementally trigger class changes for each node.
However for the Scrollbar, we don’t have a component for each annotation. We need to make up some new ones based on the set of currently highlighted nodes. So we first have to ask, what is the current set of highlighted nodes, then calculate their positions (in the container the scrollbar is associated with) and render them as part of the scrollbar. This info is currently not available, so we somehow must ask the generic annotationIndex and walk through all annos to find the ones that have active set to true. This we would need to do each time somewhere anno.setActive(..) is called. Not exactly efficient.
What if we made this a Surface API and don’t play it on the document itself, since it’s more a UI thing anyway. We should probably just reset the set of active nodes in one go, that way we can trigger the scrollbar update just once, after active nodes have been set. E.g. like this. (I thought I call the concept highlight, because active is confusing (we have active tools etc.)
surface.setHighlights(['anno1', 'anno2']);
Then we should implement some convenient event proxy that can be used by components. We could still emit node:highlighted events on individual nodes, so the node components can easily subscribe to changes, or also setting the volatile highlighted property (is convenient for the render method, so we don’t have to keep things in the component state)
surface.connect(this, {
// triggered for each node
'node:highlighted': this.onNodeHighlighted
// triggered once after setHighlights has been called
// it transports a list of node ids that have been highlighted
// can be used by the scrollbar / content panel
'nodes:highlighted': this.onNodesHighlighted
});