diff --git a/packages/ketcher-core/src/application/editor/operations/drawingEntity/index.ts b/packages/ketcher-core/src/application/editor/operations/drawingEntity/index.ts index 39487f4450..83238d1794 100644 --- a/packages/ketcher-core/src/application/editor/operations/drawingEntity/index.ts +++ b/packages/ketcher-core/src/application/editor/operations/drawingEntity/index.ts @@ -1,7 +1,6 @@ import { RenderersManager } from 'application/render/renderers/RenderersManager'; import { Operation } from 'domain/entities/Operation'; import { DrawingEntity } from 'domain/entities/DrawingEntity'; -import { Vec2 } from 'domain/entities'; export class DrawingEntityHoverOperation implements Operation { constructor(private drawingEntity: DrawingEntity) {} @@ -19,9 +18,9 @@ export class DrawingEntitySelectOperation implements Operation { } } export class DrawingEntityMoveOperation implements Operation { - constructor(private drawingEntity: DrawingEntity, private offset: Vec2) {} + constructor(private drawingEntity: DrawingEntity) {} public execute(renderersManager: RenderersManager) { - renderersManager.moveDrawingEntity(this.drawingEntity, this.offset); + renderersManager.moveDrawingEntity(this.drawingEntity); } } diff --git a/packages/ketcher-core/src/application/render/renderers/BaseMonomerRenderer.ts b/packages/ketcher-core/src/application/render/renderers/BaseMonomerRenderer.ts index 594fcf49c9..4be1061f78 100644 --- a/packages/ketcher-core/src/application/render/renderers/BaseMonomerRenderer.ts +++ b/packages/ketcher-core/src/application/render/renderers/BaseMonomerRenderer.ts @@ -4,7 +4,6 @@ import { BaseMonomer } from 'domain/entities/BaseMonomer'; import { D3SvgElementSelection } from 'application/render/types'; import { DrawingEntity } from 'domain/entities/DrawingEntity'; import { editorEvents } from 'application/editor/editorEvents'; -import { Vec2 } from 'domain/entities'; export abstract class BaseMonomerRenderer extends BaseRenderer { private editorEvents: typeof editorEvents; @@ -279,9 +278,8 @@ export abstract class BaseMonomerRenderer extends BaseRenderer { } } - public moveSelection(offset: Vec2) { + public moveSelection() { assert(this.rootElement); - this.monomer.moveRelative(offset); this.appendSelection(); this.move(); } diff --git a/packages/ketcher-core/src/application/render/renderers/BaseRenderer.ts b/packages/ketcher-core/src/application/render/renderers/BaseRenderer.ts index f4c8b1f3e1..e6f54505b0 100644 --- a/packages/ketcher-core/src/application/render/renderers/BaseRenderer.ts +++ b/packages/ketcher-core/src/application/render/renderers/BaseRenderer.ts @@ -85,7 +85,7 @@ export abstract class BaseRenderer implements IBaseRenderer { public abstract show(theme): void; public abstract drawSelection(): void; - public abstract moveSelection(offset): void; + public abstract moveSelection(): void; protected abstract appendHover( hoverArea, ): D3SvgElementSelection | void; diff --git a/packages/ketcher-core/src/application/render/renderers/PolymerBondRenderer.ts b/packages/ketcher-core/src/application/render/renderers/PolymerBondRenderer.ts index cee68bfe5b..97740d4504 100644 --- a/packages/ketcher-core/src/application/render/renderers/PolymerBondRenderer.ts +++ b/packages/ketcher-core/src/application/render/renderers/PolymerBondRenderer.ts @@ -32,7 +32,6 @@ export class PolymerBondRenderer extends BaseRenderer { public moveSelection() { assert(this.rootElement); - this.polymerBond.moveToLinkedMonomers(); this.moveStart(); this.moveEnd(); } diff --git a/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts b/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts index fccf0fa2a7..90e93dba70 100644 --- a/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts +++ b/packages/ketcher-core/src/application/render/renderers/RenderersManager.ts @@ -6,7 +6,6 @@ import { monomerFactory } from 'application/editor/operations/monomer/monomerFac import { BaseMonomer } from 'domain/entities/BaseMonomer'; import { BaseMonomerRenderer } from 'application/render/renderers/BaseMonomerRenderer'; import { PolymerBond } from 'domain/entities/PolymerBond'; -import { Vec2 } from 'domain/entities'; export class RenderersManager { private theme; @@ -27,9 +26,9 @@ export class RenderersManager { drawingEntity.baseRenderer.drawSelection(); } - public moveDrawingEntity(drawingEntity: DrawingEntity, offset: Vec2) { + public moveDrawingEntity(drawingEntity: DrawingEntity) { assert(drawingEntity.baseRenderer); - drawingEntity.baseRenderer.moveSelection(offset); + drawingEntity.baseRenderer.moveSelection(); } public addMonomer(monomer: BaseMonomer, callback?: () => void) { diff --git a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts index 40cd88b562..a2c66880d8 100644 --- a/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts +++ b/packages/ketcher-core/src/domain/entities/DrawingEntitiesManager.ts @@ -122,27 +122,28 @@ export class DrawingEntitiesManager { this.monomers.forEach((drawingEntity) => { if (drawingEntity.selected) { - command.merge( - this.createDrawingEntityMovingCommand(drawingEntity, offset), - ); + drawingEntity.moveRelative(offset); + command.merge(this.createDrawingEntityMovingCommand(drawingEntity)); } }); this.polymerBonds.forEach((drawingEntity) => { - command.merge( - this.createDrawingEntityMovingCommand(drawingEntity, offset), - ); + if ( + drawingEntity.selected || + drawingEntity.firstMonomer.selected || + drawingEntity.secondMonomer?.selected + ) { + drawingEntity.moveToLinkedMonomers(); + command.merge(this.createDrawingEntityMovingCommand(drawingEntity)); + } }); return command; } - public createDrawingEntityMovingCommand( - drawingEntity: DrawingEntity, - offset: Vec2, - ) { + public createDrawingEntityMovingCommand(drawingEntity: DrawingEntity) { const command = new Command(); - const movingCommand = new DrawingEntityMoveOperation(drawingEntity, offset); + const movingCommand = new DrawingEntityMoveOperation(drawingEntity); command.addOperation(movingCommand); return command;