Commit 4feb920d authored by Randall Leeds's avatar Randall Leeds

Prune empties in threading plugin

I had decided not to do this initially in order to show annotations
that were missing. We'll have to decide how we want to show the holes,
but it's much better if we prune the containers that aren't used so
that we don't end up with empty threads sitting around all over the
place.

The only tricky thing is that when new annotations are loaded we must
thread everything again or existing containers that were lifted up to
the root will not attach themselves to newly loaded parents.
parent bac08b10
......@@ -48,18 +48,17 @@ class Annotator.Plugin.Threading extends Annotator.Plugin
return # no dupes
prev.addChild(thread)
this.pruneEmpties(@root)
@root
beforeAnnotationCreated: (annotation) =>
this.thread([annotation])
annotationDeleted: ({id}) =>
container = @idTable[id]
return unless container?
container = this.getContainer id
container.message = null
if container.children.length == 0
container.parent.removeChild(container)
delete @idTable[id]
this.pruneEmpties(@root)
annotationsLoaded: (annotations) =>
this.thread(annotations)
messages = (@root.flattenChildren() or []).concat(annotations)
this.thread(messages)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment