diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 9d01a235ef..b6204fc260 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -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) diff --git a/src/calibre/gui2/tweak_book/preview.py b/src/calibre/gui2/tweak_book/preview.py index 53c0ba1794..59e0e8c58d 100644 --- a/src/calibre/gui2/tweak_book/preview.py +++ b/src/calibre/gui2/tweak_book/preview.py @@ -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) diff --git a/src/pyj/editor.pyj b/src/pyj/editor.pyj index 2860ce4475..6b7fd4538c 100644 --- a/src/pyj/editor.pyj +++ b/src/pyj/editor.pyj @@ -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