Navigate to CFIs correctly in paged mode and fix typo in current_column_location()

This commit is contained in:
Kovid Goyal 2012-06-19 19:03:01 +05:30
parent 957bd0512f
commit fc4309539b
3 changed files with 15 additions and 12 deletions

Binary file not shown.

View File

@ -161,7 +161,7 @@ class PagedDisplay
# The location of the left edge of the left most column currently
# visible in the viewport
x = window.pageXOffset + Math.max(10, this.current_margin_side)
edge = Math.floor(x/this.page_width)
edge = Math.floor(x/this.page_width) * this.page_width
while edge < x
edge += this.page_width
return edge - this.page_width
@ -237,6 +237,18 @@ class PagedDisplay
# selection
this.scroll_to_xpos(left+5)
jump_to_cfi: (cfi) ->
# Jump to the position indicated by the specified conformal fragment
# indicator (requires the cfi.coffee library). When in paged mode, the
# scroll is performed so that the column containing the position
# pointed to by the cfi is the left most column in the viewport
window.cfi.scroll_to(cfi, (x, y) =>
if this.in_paged_mode
this.scroll_to_xpos(x)
else
window.scrollTo(0, y)
)
if window?
window.paged_display = new PagedDisplay()

View File

@ -37,17 +37,8 @@ class PagePosition(object):
def scroll_to_cfi(self, cfi):
if cfi:
cfi = json.dumps(cfi)
self.document.mainFrame().evaluateJavaScript('''
function fix_scroll() {
/* cfi.scroll_to() uses scrollIntoView() which can result
in scrolling along the x-axis. So we
explicitly scroll to x=0.
*/
scrollTo(0, window.pageYOffset)
}
window.cfi.scroll_to(%s, fix_scroll);
'''%cfi)
self.document.mainFrame().evaluateJavaScript(
'paged_display.jump_to_cfi(%s)'%cfi)
@property
def current_pos(self):