From 1b5f37007b57a92500f85ad12788263b235555d7 Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Tue, 25 Apr 2023 20:28:47 -0400 Subject: [PATCH] [Mode2UpLit] Fix scale outdated when changing mode --- src/BookReader/Mode2Up.js | 5 ++--- src/BookReader/Mode2UpLit.js | 3 +++ tests/jest/BookReader/Mode2Up.test.js | 6 ++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BookReader/Mode2Up.js b/src/BookReader/Mode2Up.js index 800d4eb4f..587f9ea27 100644 --- a/src/BookReader/Mode2Up.js +++ b/src/BookReader/Mode2Up.js @@ -58,6 +58,7 @@ export class Mode2Up { }); } else { await this.mode2UpLit.jumpToIndex(startLeaf, { smooth: false }); + this.resizePageView(); } this.mode2UpLit.style.opacity = '1'; }); @@ -93,9 +94,7 @@ export class Mode2Up { resizePageView() { this.mode2UpLit.htmlDimensionsCacher.updateClientSizes(); - const translation = this.mode2UpLit.worldOffset; - const hasTranslation = translation.x || translation.y; - if (hasTranslation && this.mode2UpLit.autoFit == 'none') { + if (this.mode2UpLit.scale < this.mode2UpLit.initialScale && this.mode2UpLit.autoFit == 'none') { this.mode2UpLit.autoFit = 'auto'; } if (this.mode2UpLit.autoFit != 'none') { diff --git a/src/BookReader/Mode2UpLit.js b/src/BookReader/Mode2UpLit.js index cb3425821..e79b3de5c 100644 --- a/src/BookReader/Mode2UpLit.js +++ b/src/BookReader/Mode2UpLit.js @@ -39,6 +39,8 @@ export class Mode2UpLit extends LitElement { @property({ type: Number }) scale = 1; + initialScale = 1; + /** Position (in unit-less, [0, 1] coordinates) in client to scale around */ @property({ type: Object }) scaleCenter = { x: 0.5, y: 0.5 }; @@ -317,6 +319,7 @@ export class Mode2UpLit extends LitElement { ).filter(p => p); this.htmlDimensionsCacher.updateClientSizes(); this.resizeViaAutofit(page); + this.initialScale = this.scale; } /** @param {PageModel} page */ diff --git a/tests/jest/BookReader/Mode2Up.test.js b/tests/jest/BookReader/Mode2Up.test.js index 362ff331a..b96e668b8 100644 --- a/tests/jest/BookReader/Mode2Up.test.js +++ b/tests/jest/BookReader/Mode2Up.test.js @@ -80,15 +80,13 @@ describe('Mode2Up', () => { const resizeViaAutofitSpy = sinon.spy(mode2Up.mode2UpLit, 'resizeViaAutofit'); const recenterStub = sinon.stub(mode2Up.mode2UpLit, 'recenter'); - mode2Up.worldOffset = { x: 0, y: 0 }; mode2Up.resizePageView(); - expect(updateClientSizesSpy.called).toBe(true); expect(resizeViaAutofitSpy.called).toBe(true); expect(recenterStub.called).toBe(true); - // // Test with translation and autoFit as 'none' - mode2Up.mode2UpLit.worldOffset = { x: 10, y: 10 }; + // Test with scale and autoFit as 'none' + mode2Up.mode2UpLit.scale = 0.1; mode2Up.mode2UpLit.autoFit = 'none'; mode2Up.resizePageView();