diff --git a/packages/ketcher-react/src/script/editor/Editor.ts b/packages/ketcher-react/src/script/editor/Editor.ts index cd34b064c3..70b73f53f4 100644 --- a/packages/ketcher-react/src/script/editor/Editor.ts +++ b/packages/ketcher-react/src/script/editor/Editor.ts @@ -330,6 +330,27 @@ class Editor implements KetcherEditor { return this.render.options.zoom } + zoomAccordingContent() { + this.zoom(1) + const clientAreaBoundingBox = this.render.clientArea.getBoundingClientRect() + const paper = this.render.paper + const MIN_ZOOM_VALUE = 0.1 + const MAX_ZOOM_VALUE = 1 + const newZoomValue = + paper.height - clientAreaBoundingBox.height > + paper.width - clientAreaBoundingBox.width + ? clientAreaBoundingBox.height / paper.height + : clientAreaBoundingBox.width / paper.width + + if (newZoomValue < MAX_ZOOM_VALUE) { + this.zoom( + newZoomValue < MIN_ZOOM_VALUE + ? MIN_ZOOM_VALUE + : Number(newZoomValue.toFixed(2)) + ) + } + } + selection(ci?: any) { if (arguments.length === 0) { return this._selection // eslint-disable-line diff --git a/packages/ketcher-react/src/script/ui/state/shared.ts b/packages/ketcher-react/src/script/ui/state/shared.ts index ed2e32b5ca..e6e9bbd86d 100644 --- a/packages/ketcher-react/src/script/ui/state/shared.ts +++ b/packages/ketcher-react/src/script/ui/state/shared.ts @@ -169,6 +169,9 @@ export function load(struct: Struct, options?) { } else { editor.struct(parsedStruct) } + + editor.zoomAccordingContent() + dispatch(setAnalyzingFile(false)) dispatch({ type: 'MODAL_CLOSE' }) } catch (err: any) {