mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix searching in paged mode
This commit is contained in:
parent
100dd0dd45
commit
c6bf118b38
Binary file not shown.
@ -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()
|
||||
|
||||
|
@ -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()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user