Commit c42ee255 authored by Randall Leeds's avatar Randall Leeds

Fuzzy anchoring for PDF

parent 4eb46506
......@@ -134,6 +134,37 @@ exports.anchor = (selectors) ->
return range
)
if quote?
promise = promise.catch ->
{pagesCount} = PDFViewerApplication.pdfViewer
pageSearches = for pageIndex in [0...pagesCount]
page = getPage(pageIndex)
continue unless page.textLayer?.renderingDone
content = getPageTextContent(pageIndex)
offset = getPageOffset(pageIndex)
Promise.all([content, offset, page]).then((results) ->
[content, offset, page] = results
quoteOptions = {root: page.textLayer.textLayerDiv}
if position?
# XXX: must be on one page
start = position.start - offset
end = position.end - offset
quoteOptions.position = {start, end}
return TextQuoteAnchor
.fromSelector(quote, quoteOptions)
.toRange(quoteOptions)
).catch(-> null)
return Promise.all(pageSearches).then((results) ->
for result in results when result?
return result
throw new Error('quote not found')
)
return promise
......
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