Skip to content

Commit

Permalink
[Mode2UpLit] Fix scale outdated when changing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrini committed Apr 26, 2023
1 parent 1c4be78 commit 1b5f370
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/BookReader/Mode2Up.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Mode2Up {
});
} else {
await this.mode2UpLit.jumpToIndex(startLeaf, { smooth: false });
this.resizePageView();
}
this.mode2UpLit.style.opacity = '1';
});
Expand Down Expand Up @@ -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') {
Expand Down
3 changes: 3 additions & 0 deletions src/BookReader/Mode2UpLit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 2 additions & 4 deletions tests/jest/BookReader/Mode2Up.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 1b5f370

Please sign in to comment.