From 448a7a27cbbab63d72d2eecedb681d29b09e50b4 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 11 Jan 2018 12:06:44 +0100 Subject: [PATCH 1/2] Ensure that the `PDFHistory._maxUid` property is correctly updated when initializing/navigating the history This is a follow-up to commit e7721243399773fbc549ecb9ce83822df08dacde, in PR 8994, to cover a couple of cases missed there. --- web/pdf_history.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/pdf_history.js b/web/pdf_history.js index 756a4de54..57a4d1bbd 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -133,6 +133,9 @@ class PDFHistory { let destination = state.destination; this._updateInternalState(destination, state.uid, /* removeTemporary = */ true); + if (this._uid > this._maxUid) { + this._maxUid = this._uid; + } if (destination.rotation !== undefined) { this.initialRotation = destination.rotation; @@ -510,6 +513,9 @@ class PDFHistory { let destination = state.destination; this._updateInternalState(destination, state.uid, /* removeTemporary = */ true); + if (this._uid > this._maxUid) { + this._maxUid = this._uid; + } if (isValidRotation(destination.rotation)) { this.linkService.rotation = destination.rotation; From e20eacd484d0a887648803d7d15b22ecf0efeee3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 11 Jan 2018 12:28:34 +0100 Subject: [PATCH 2/2] Allow overwriting temporary, in addition to empty, history entries on 'pagehide' When navigating away from the viewer, there's no good reason for disallowing replacement of a *temporary* history entry (in addition to empty ones). Given that the current position is temporarily added to the browser history using a (short) timeout, the history entry will most likely already be correct when the 'pagehide' event fires. However, if the user is quick enough that might not always be the case, in which case the adjusted logic may help. --- web/pdf_history.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/pdf_history.js b/web/pdf_history.js index 57a4d1bbd..5bdc17b92 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -547,10 +547,10 @@ class PDFHistory { _boundEvents.pageHide = (evt) => { // Attempt to push the `this._position` into the browser history when // navigating away from the document. This is *only* done if the history - // is currently empty, since otherwise an existing browser history entry + // is empty/temporary, since otherwise an existing browser history entry // will end up being overwritten (given that new entries cannot be pushed // into the browser history when the 'unload' event has already fired). - if (!this._destination) { + if (!this._destination || this._destination.temporary) { this._tryPushCurrentPosition(); } };