mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #257 from sharelatex/fix-synctex-position-calculation
Fix synctex position calculation
This commit is contained in:
commit
d0a273fac1
3 changed files with 40 additions and 7 deletions
|
@ -354,18 +354,35 @@ define [
|
|||
deferred.reject()
|
||||
return deferred.promise
|
||||
|
||||
# FIXME: this actually works better if it's halfway across the
|
||||
# page (or the visible part of the page). Synctex doesn't
|
||||
# always find the right place in the file when the point is at
|
||||
# the edge of the page, it sometimes returns the start of the
|
||||
# next paragraph instead.
|
||||
h = position.offset.left
|
||||
|
||||
# Compute the vertical position to pass to synctex, which
|
||||
# works with coordinates increasing from the top of the page
|
||||
# down. This matches the browser's DOM coordinate of the
|
||||
# click point, but the pdf position is measured from the
|
||||
# bottom of the page so we need to invert it.
|
||||
if options.fromPdfPosition and position.pageSize?.height?
|
||||
v = (position.pageSize.height - position.offset.top) or 0 # measure from pdf point (inverted)
|
||||
else
|
||||
v = position.offset.top or 0 # measure from html click position
|
||||
|
||||
# It's not clear exactly where we should sync to if it wasn't directly
|
||||
# clicked on, but a little bit down from the very top seems best.
|
||||
if options.includeVisualOffset
|
||||
position.offset.top = position.offset.top + 80
|
||||
v += 72 # use the same value as in pdfViewer highlighting visual offset
|
||||
|
||||
$http({
|
||||
url: "/project/#{ide.project_id}/sync/pdf",
|
||||
method: "GET",
|
||||
params: {
|
||||
page: position.page + 1
|
||||
h: position.offset.left.toFixed(2)
|
||||
v: position.offset.top.toFixed(2)
|
||||
h: h.toFixed(2)
|
||||
v: v.toFixed(2)
|
||||
clsiserverid:ide.clsiServerId
|
||||
isolated: perUserCompile
|
||||
}
|
||||
|
@ -396,7 +413,7 @@ define [
|
|||
|
||||
$scope.syncToCode = () ->
|
||||
synctex
|
||||
.syncToCode($scope.pdf.position, includeVisualOffset: true)
|
||||
.syncToCode($scope.pdf.position, includeVisualOffset: true, fromPdfPosition: true)
|
||||
.then (data) ->
|
||||
{doc, line} = data
|
||||
ide.editorManager.openDoc(doc, gotoLine: line)
|
||||
|
|
|
@ -50,7 +50,11 @@ define [
|
|||
scope.scale = { scaleMode: 'scale_mode_fit_width' }
|
||||
|
||||
if (position = localStorage("pdf.position.#{attrs.key}"))
|
||||
scope.position = { page: +position.page, offset: { "top": +position.offset.top, "left": +position.offset.left } }
|
||||
scope.position =
|
||||
page: +position.page,
|
||||
offset:
|
||||
"top": +position.offset.top
|
||||
"left": +position.offset.left
|
||||
|
||||
#scope.position = pdfListView.getPdfPosition(true)
|
||||
|
||||
|
|
|
@ -187,7 +187,8 @@ define [
|
|||
# console.log 'converted to offset = ', pdfOffset
|
||||
newPosition = {
|
||||
"page": topPageIdx,
|
||||
"offset" : { "top" : pdfOffset[1], "left": 0 }
|
||||
"offset" : { "top" : pdfOffset[1], "left": 0}
|
||||
"pageSize": { "height": viewport.viewBox[3], "width": viewport.viewBox[2] }
|
||||
}
|
||||
return newPosition
|
||||
|
||||
|
@ -208,6 +209,8 @@ define [
|
|||
return $scope.document.getPdfViewport(page.pageNum).then (viewport) ->
|
||||
page.viewport = viewport
|
||||
pageOffset = viewport.convertToViewportPoint(offset.left, offset.top)
|
||||
# if the passed-in position doesn't have the page height/width add them now
|
||||
position.pageSize ?= {"height": viewport.viewBox[3], "width": viewport.viewBox[2]}
|
||||
# console.log 'addition offset =', pageOffset
|
||||
# console.log 'total', pageTop + pageOffset[1]
|
||||
Math.round(pageTop + pageOffset[1] + currentScroll) ## 10 is margin
|
||||
|
@ -513,8 +516,17 @@ define [
|
|||
|
||||
first = highlights[0]
|
||||
|
||||
pageNum = scope.pages[first.page].pageNum
|
||||
# switching between split and full pdf views can cause
|
||||
# highlights to appear before rendering
|
||||
if !scope.pages
|
||||
return # ignore highlight scroll if still rendering
|
||||
|
||||
pageNum = scope.pages[first.page]?.pageNum
|
||||
|
||||
if !pageNum?
|
||||
return # ignore highlight scroll if page not found
|
||||
|
||||
# use a visual offset of 72pt to match the offset in PdfController syncToCode
|
||||
scope.document.getPdfViewport(pageNum).then (viewport) ->
|
||||
position = {
|
||||
page: first.page
|
||||
|
|
Loading…
Reference in a new issue