From f75458224bfdc311b4322478c979acab002b117e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 Jul 2013 22:11:44 +0530 Subject: [PATCH] E-book viewer: Fix page position incorrect after startup bookmark E-book viewer: Fix a bug that could cause the reported position to be incorrect immediately after opening a previously opened book. This also fixes the Back button not working if a link is clicked on the page immediately after opening the book. --- resources/compiled_coffeescript.zip | Bin 71881 -> 71983 bytes .../ebooks/oeb/display/indexing.coffee | 4 ++++ src/calibre/gui2/viewer/main.py | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/resources/compiled_coffeescript.zip b/resources/compiled_coffeescript.zip index e092b53157f3c30f95712db0b597358b744dc08a..3c5f0e80c6f57fd0b309fa8ea039fcfcd3f1e310 100644 GIT binary patch delta 328 zcmX@Pk!AfR7Ty4FW)=|!5LmwU8ZZ_gK z;NZzjQ_xUM%uCM5FDjmFs3km^U4nOV-3N}zp{yd4A4utJUL>x?jHzm#9OvYFja(pA zn;%Hs6W(msdA(<{-eiuATtE4E8JR?w;f|QjCC(^4-Byf|e|oJrBgb?baYhjZOgDku z3?&+(z%HD=P>j)(=|BO5^Hz*eZhD9~qZHHBDv*dL)5I2t%mr~qBPNGQlfN&JovtXs zsKwMe6C#l$!DzrV^%sP*Qi73Zx~LeV26F{F<8%ixMkNteHjss!K)8U3fuT~25y%4o D7KK^O delta 278 zcmZ3#iRI)*mhBbnjLiI!%q$`dARy?u-)T!=LB~8%1_lt8o4lb)Z1ct_1CGg_3q&?+ zCWkSD7?U-VbvA!Y+a$b^uO@2q{HohM)2qc8xu)NcV3cD98Z-T;1f!A`Ba;X-4r9TV z!3akF$s4Ogr!$K)nljy10ki$Z8RcXSnuxl%M=>yfury3DnBJfVR<%ovQDk~1P$`o^ zCs06s`U-JIEhe4GV9A%_j7Chi7fhFxV033vSTT9wOzG*35{z2R2Aqu3*GVuch_JGO R4C4gC1xySK!eWd-9suzoMJxaS diff --git a/src/calibre/ebooks/oeb/display/indexing.coffee b/src/calibre/ebooks/oeb/display/indexing.coffee index efe42199e9..357128fce9 100644 --- a/src/calibre/ebooks/oeb/display/indexing.coffee +++ b/src/calibre/ebooks/oeb/display/indexing.coffee @@ -50,6 +50,8 @@ class BookIndexing this.last_check = [null, null] cache_valid: (anchors) -> + if not anchors + return false for a in anchors if not Object.prototype.hasOwnProperty.call(this.cache, a) return false @@ -65,6 +67,8 @@ class BookIndexing return this.cache ans = {} + if not anchors + return ans for anchor in anchors elem = document.getElementById(anchor) if elem == null diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py index 113e1201e2..8681a0fe21 100644 --- a/src/calibre/gui2/viewer/main.py +++ b/src/calibre/gui2/viewer/main.py @@ -772,12 +772,14 @@ class EbookViewer(MainWindow, Ui_EbookViewer): self.scrolled(self.view.scroll_fraction) def internal_link_clicked(self, frac): + self.update_page_number() # Ensure page number is accurate as it is used for history self.history.add(self.pos.value()) def link_clicked(self, url): path = os.path.abspath(unicode(url.toLocalFile())) frag = None if path in self.iterator.spine: + self.update_page_number() # Ensure page number is accurate as it is used for history self.history.add(self.pos.value()) path = self.iterator.spine[self.iterator.spine.index(path)] if url.hasFragment(): @@ -913,6 +915,14 @@ class EbookViewer(MainWindow, Ui_EbookViewer): else: self.view.document.page_position.restore() self.view.document.after_resize() + # For some reason scroll_fraction returns incorrect results in paged + # mode for some time after a resize is finished. No way of knowing + # exactly how long, so we update it in a second, in the hopes that it + # will be enough *most* of the time. + QTimer.singleShot(1000, self.update_page_number) + + def update_page_number(self): + self.set_page_number(self.view.document.scroll_fraction) def close_progress_indicator(self): self.pi.stop()