diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index bacbcf8aaf..dc290df6e3 100644 Binary files a/resources/compiled_coffeescript.zip and b/resources/compiled_coffeescript.zip differ diff --git a/src/calibre/ebooks/oeb/display/paged.coffee b/src/calibre/ebooks/oeb/display/paged.coffee index a65a452483..f4dcf4309e 100644 --- a/src/calibre/ebooks/oeb/display/paged.coffee +++ b/src/calibre/ebooks/oeb/display/paged.coffee @@ -140,6 +140,9 @@ class PagedDisplay scroll_to_xpos: (xpos) -> # Scroll so that the column containing xpos is the left most column in # the viewport + if typeof(xpos) != 'number' + log(xpos, 'is not a number, cannot scroll to it!') + return pos = 0 until (pos <= xpos < pos + this.page_width) pos += this.page_width @@ -206,6 +209,9 @@ class PagedDisplay return ans jump_to_anchor: (name) -> + # Jump to the element identified by anchor name. Ensures that the left + # most column in the viewport is the column containing the start of the + # element and that the scroll position is at the start of the column. elem = document.getElementById(name) if !elem elems = document.getElementsByName(name) @@ -218,6 +224,16 @@ class PagedDisplay # Ensure we are scrolled to the column containing elem this.scroll_to_xpos(absleft(elem) + 5) + snap_to_selection: () -> + sel = window.getSelection() + r = sel.getRangeAt(0).getBoundingClientRect() + node = sel.anchorNode + left = viewport_to_document(r.left, r.top, doc=node.ownerDocument)[0] + if this.in_paged_mode + # Ensure we are scrolled to the column containing the start of the + # selection + this.scroll_to_xpos(left+5) + if window? window.paged_display = new PagedDisplay() diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 602f024de3..f0b6668c1d 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -588,9 +588,11 @@ class DocumentView(QWebView): # {{{ return property(fget=fget, fset=fset) def search(self, text, backwards=False): - if backwards: - return self.findText(text, self.document.FindBackward) - return self.findText(text) + flags = self.document.FindBackward if backwards else self.document.FindFlags(0) + found = self.findText(text, flags) + if found and self.document.in_paged_mode: + self.document.javascript('paged_display.snap_to_selection()') + return found def path(self): return os.path.abspath(unicode(self.url().toLocalFile()))