From dc7f748d8f03aba605631965e21fb3ebfa675efa Mon Sep 17 00:00:00 2001 From: Johannes Bunk Date: Mon, 15 Apr 2024 18:28:03 +0200 Subject: [PATCH] fix scroll bug --- packages/core/src/RenderingEngine/StackViewport.ts | 11 ++++++++--- packages/core/src/types/IStackViewport.ts | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/core/src/RenderingEngine/StackViewport.ts b/packages/core/src/RenderingEngine/StackViewport.ts index 2b0312d83c..71f13c559b 100644 --- a/packages/core/src/RenderingEngine/StackViewport.ts +++ b/packages/core/src/RenderingEngine/StackViewport.ts @@ -2445,8 +2445,9 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader { /** * Loads the image based on the provided imageIdIndex * @param imageIdIndex - number represents imageId index + * @param overwriteScrollIndex - can be used to also set the start position of scroll() to this index */ - private async _setImageIdIndex(imageIdIndex: number): Promise { + private async _setImageIdIndex(imageIdIndex: number, overwriteScrollIndex: boolean = false): Promise { if (imageIdIndex >= this.imageIds.length) { throw new Error( `ImageIdIndex provided ${imageIdIndex} is invalid, the stack only has ${this.imageIds.length} elements` @@ -2455,6 +2456,9 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader { // Update the state of the viewport to the new imageIdIndex; this.currentImageIdIndex = imageIdIndex; + if (overwriteScrollIndex) { + this.targetImageIdIndex = this.currentImageIdIndex; + } this.hasPixelSpacing = true; this.viewportStatus = ViewportStatus.PRE_RENDER; @@ -2583,8 +2587,9 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader { * * @param imageIdIndex - number represents imageId index in the list of * provided imageIds in setStack + * @param overwriteScrollIndex - can be used to also set the start position of scroll() to this index */ - public setImageIdIndex(imageIdIndex: number): Promise { + public setImageIdIndex(imageIdIndex: number, overwriteScrollIndex: boolean = false): Promise { this._throwIfDestroyed(); // If we are already on this imageId index, stop here @@ -2593,7 +2598,7 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader { } // Otherwise, get the imageId and attempt to display it - const imageIdPromise = this._setImageIdIndex(imageIdIndex); + const imageIdPromise = this._setImageIdIndex(imageIdIndex, overwriteScrollIndex); return imageIdPromise; } diff --git a/packages/core/src/types/IStackViewport.ts b/packages/core/src/types/IStackViewport.ts index 5d7dfce45a..754eaa4c9f 100644 --- a/packages/core/src/types/IStackViewport.ts +++ b/packages/core/src/types/IStackViewport.ts @@ -158,7 +158,10 @@ export default interface IStackViewport extends IViewport { * Loads the image based on the provided imageIdIndex. It is an Async function which * returns a promise that resolves to the imageId. */ - setImageIdIndex(imageIdIndex: number): Promise; + setImageIdIndex( + imageIdIndex: number, + overwriteScrollIndex: boolean + ): Promise; /** * Calibrates the image with new metadata that has been added for imageId. To calibrate * a viewport, you should add your calibration data manually to