Skip to content

Commit

Permalink
#6370 - Inconsistent zoom behavior when inserting a molecule via setM…
Browse files Browse the repository at this point in the history
…olecule and Paste from Clipboard/Open from File (#6373) (#6376)

* #6370 - Inconsistent zoom behavior when inserting a molecule via setMolecule and Paste from Clipboard/Open from File
- added autozoom for setMolecule and addFragment in macro mode

#6375 - Ketcher renders editor twice in dev mode
- removed react strict mode from editor
  • Loading branch information
rrodionov91 authored Jan 28, 2025
1 parent 17c8606 commit 7cd4acd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions packages/ketcher-core/src/application/ketcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,17 @@ export class Ketcher {
}

async setMolecule(structStr: string): Promise<void | undefined> {
if (CoreEditor.provideEditorInstance()?.isSequenceEditInRNABuilderMode)
return;
const macromoleculesEditor = CoreEditor.provideEditorInstance();

if (macromoleculesEditor?.isSequenceEditInRNABuilderMode) return;

runAsyncAction<void>(async () => {
assert(typeof structStr === 'string');

if (window.isPolymerEditorTurnedOn) {
deleteAllEntitiesOnCanvas();
await parseAndAddMacromoleculesOnCanvas(structStr, this.structService);
macromoleculesEditor?.zoomToStructuresIfNeeded();
} else {
const struct: Struct = await prepareStructToRender(
structStr,
Expand Down Expand Up @@ -411,14 +413,22 @@ export class Ketcher {
}

async addFragment(structStr: string): Promise<void | undefined> {
if (CoreEditor.provideEditorInstance()?.isSequenceEditInRNABuilderMode)
return;
const macromoleculesEditor = CoreEditor.provideEditorInstance();

if (macromoleculesEditor?.isSequenceEditInRNABuilderMode) return;

runAsyncAction<void>(async () => {
assert(typeof structStr === 'string');

if (window.isPolymerEditorTurnedOn) {
const isCanvasEmptyBeforeOpenStructure =
!macromoleculesEditor.drawingEntitiesManager.hasDrawingEntities;

await parseAndAddMacromoleculesOnCanvas(structStr, this.structService);

if (isCanvasEmptyBeforeOpenStructure) {
macromoleculesEditor?.zoomToStructuresIfNeeded();
}
} else {
const struct: Struct = await prepareStructToRender(
structStr,
Expand Down
6 changes: 3 additions & 3 deletions packages/ketcher-react/src/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lazy, StrictMode, Suspense, useState } from 'react';
import { lazy, Suspense, useState } from 'react';
import { MicromoleculesEditor, EditorProps } from './MicromoleculesEditor';
import { ModeControl } from './script/ui/views/toolbars/ModeControl';
import { LoadingCircles } from './script/ui/views/components';
Expand Down Expand Up @@ -36,7 +36,7 @@ export const Editor = (props: Props) => {
) : undefined;

return (
<StrictMode>
<>
{showPolymerEditor ? (
<Suspense
fallback={
Expand All @@ -61,6 +61,6 @@ export const Editor = (props: Props) => {
/>
</Suspense>
)}
</StrictMode>
</>
);
};

0 comments on commit 7cd4acd

Please sign in to comment.