Go to anchor explicitly in the preview

This commit is contained in:
Kovid Goyal 2018-07-28 10:08:12 +05:30
parent 50ed25a6d9
commit 883717039e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 3 deletions

View File

@ -1260,7 +1260,9 @@ class Boss(QObject):
_('Editing files of type %s is not supported' % mt), show=True)
editor = self.edit_file(name, syntax)
if anchor and editor is not None:
if not editor.go_to_anchor(anchor) and show_anchor_not_found:
if editor.go_to_anchor(anchor):
self.gui.preview.go_to_anchor(anchor)
elif show_anchor_not_found:
error_dialog(self.gui, _('Not found'), _(
'The anchor %s was not found in this file') % anchor, show=True)

View File

@ -492,6 +492,9 @@ class Preview(QWidget):
def find_prev(self):
self.find('prev')
def go_to_anchor(self, anchor):
self.view._page.go_to_anchor(anchor)
def request_sync(self, tagname, href, lnum):
if self.current_name:
c = current_container()
@ -501,7 +504,7 @@ class Preview(QWidget):
else:
name = c.href_to_name(href, self.current_name) if href else None
if name == self.current_name:
return self.view._page.go_to_anchor(urlparse(href).fragment)
return self.go_to_anchor(urlparse(href).fragment)
if name and c.exists(name) and c.mime_map[name] in OEB_DOCS:
return self.link_clicked.emit(name, urlparse(href).fragment or TOP)
self.sync_requested.emit(self.current_name, lnum)

View File

@ -336,7 +336,7 @@ class PreviewIntegration:
address = get_sourceline_address(e)
# Find the closest containing link, if any
href = tn = ''
while e and e != document.body and e != document and (tn is not 'a' or not href):
while e and e is not document.body and e is not document and e is not document.documentElement and (tn is not 'a' or not href):
tn = e.tagName.toLowerCase() if e.tagName else ''
href = e.getAttribute('href')
e = e.parentNode