Commit 806ad948 authored by Randall Leeds's avatar Randall Leeds

Remove all the fancy throttling of anchoring

This is premature optimization and makes things way more difficult
to reason about.
parent e693f4ba
......@@ -149,6 +149,12 @@ module.exports = class Guest extends Annotator
setupAnnotation: (annotation) ->
self = this
anchors = []
anchoredTargets = []
deadHighlights = []
annotation.target ?= []
locate = (target) ->
options = {ignoreSelector: '[class^="annotator-"]'}
return new Promise(raf)
......@@ -165,10 +171,15 @@ module.exports = class Guest extends Annotator
return anchor
return anchor
setup = ->
anchors = []
anchoredTargets = []
deadHighlights = []
sync = (anchors) ->
annotation.$orphan = anchors.length > 0
for anchor in anchors
if anchor.range?
annotation.$orphan = false
self.anchors = self.anchors.concat(anchors)
self.plugins.BucketBar.update()
self.plugins.CrossFrame.sync([annotation])
for anchor in self.anchors.splice(0, self.anchors.length)
if anchor.annotation is annotation
......@@ -189,26 +200,7 @@ module.exports = class Guest extends Annotator
anchor = locate(target).then(highlight)
anchors.push(anchor)
return Promise.all(anchors)
sync = (anchors) ->
annotation.$orphan = anchors.length > 0
for anchor in anchors
if anchor.range?
annotation.$orphan = false
self.anchors = self.anchors.concat(anchors)
self.plugins.BucketBar.update()
self.plugins.CrossFrame.sync([annotation])
cleanup = ->
delete annotation.anchors
annotation.target ?= []
annotation.anchors ?= Promise.resolve(annotation.anchors)
.then(setup)
.then(sync)
.then(cleanup, cleanup)
Promise.all(anchors).then(sync)
return annotation
......
......@@ -6,8 +6,6 @@ class PDF extends Annotator.Plugin
documentLoaded: null
observer: null
pdfViewer: null
updatePromise: null
updateTimeout: null
pluginInit: ->
@pdfViewer = PDFViewerApplication.pdfViewer
......@@ -59,17 +57,11 @@ class PDF extends Annotator.Plugin
return {title, link}
update: ->
self = this
{annotator, pdfViewer} = this
_throttle = ->
if self.updateTimeout?
clearTimeout(self.updateTimeout)
self.updateTimeout = setTimeout(_update, 200)
_update = ->
anchors = []
annotations = []
stableAnchors = []
pendingAnchors = []
refreshAnnotations = []
for page in pdfViewer.pages when page.textLayer?.renderingDone
div = page.div ? page.el
......@@ -82,27 +74,22 @@ class PDF extends Annotator.Plugin
if placeholder?
placeholder.parentNode.removeChild(placeholder)
for anchor in annotator.anchors when anchor.annotation not in annotations
unless anchor.range? and anchor.highlights?
delete anchor.range
annotations.push(anchor.annotation)
for anchor in annotator.anchors when anchor.highlights?
if anchor.annotation in refreshAnnotations
continue
for hl in anchor.highlights
if not document.body.contains(hl)
delete anchor.highlights
delete anchor.range
annotations.push(anchor.annotation)
refreshAnnotations.push(anchor.annotation)
break
for annotation in annotations
for annotation in refreshAnnotations
annotator.setupAnnotation(annotation)
anchors.push(annotation.anchors)
self.updateTimeout = null
self.updatePromise = Promise.all(anchors)
pendingAnchors.push(annotation.anchors)
@annotator.plugins.BucketBar?.update()
Promise.resolve(@updatePromise).then(_throttle)
annotator.plugins.BucketBar?.update()
Annotator.Plugin.PDF = PDF
......
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