Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backmerge: Macro: #3899 - Attachment points do not disappear when hover is removed from some monomers. #4034

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ export abstract class BaseMonomerRenderer extends BaseRenderer {
}
}

public updateAttachmentPoints() {
this.hoveredAttachmenPoint = null;
if (!this.rootElement) return;
if (this.attachmentPoints.length > 0) {
this.attachmentPoints.forEach((point) => {
point.updateAttachmentPointStyleForHover();
});
} else {
this.drawAttachmentPoints();
}
}

public redrawAttachmentPointsCoordinates() {
const chosenAttachmentPointName =
this.monomer.chosenFirstAttachmentPointForBond;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class RenderersManager {
) {
this.hoverDrawingEntity(monomer as DrawingEntity);
monomer.renderer?.hoverAttachmenPoint(attachmentPointName);
monomer.renderer?.redrawAttachmentPoints();
monomer.renderer?.updateAttachmentPoints();
}

public update(modelChanges: Command) {
Expand Down
24 changes: 19 additions & 5 deletions packages/ketcher-core/src/domain/AttachmentPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getSearchFunction,
} from './helpers/attachmentPointCalculations';
import { editorEvents } from 'application/editor/editorEvents';
import { AttachmentPointConstructorParams } from './types';
import { AttachmentPointConstructorParams, AttachmentPointName } from './types';

export class AttachmentPoint {
static attachmentPointVector = 12;
Expand Down Expand Up @@ -188,6 +188,9 @@ export class AttachmentPoint {
event.attachmentPointName = this.attachmentPointName;
this.editorEvents.mouseOverAttachmentPoint.dispatch(event);
})
.on('mouseleave', (event) => {
this.editorEvents.mouseLeaveAttachmentPoint.dispatch(event);
})
.on('mousedown', (event) => {
event.attachmentPointName = this.attachmentPointName;
this.editorEvents.mouseDownAttachmentPoint.dispatch(event);
Expand All @@ -197,10 +200,6 @@ export class AttachmentPoint {
this.editorEvents.mouseUpAttachmentPoint.dispatch(event);
});

this.element.on('mouseleave', (event) => {
this.editorEvents.mouseLeaveAttachmentPoint.dispatch(event);
});

return hoverableAreaElement;
}

Expand Down Expand Up @@ -263,6 +262,21 @@ export class AttachmentPoint {
return attachmentPoint;
}

public updateAttachmentPointStyleForHover() {
const isAttachmentPointUsed = this.monomer.isAttachmentPointUsed(
this.attachmentPointName as AttachmentPointName,
);
if (isAttachmentPointUsed) {
this.attachmentPoint
?.select('line')
.style('stroke', AttachmentPoint.colors.fillUsed);
this.attachmentPoint
?.select('circle')
.style('fill', AttachmentPoint.colors.fillUsed)
.attr('stroke', 'white');
}
}

public rotateToAngle(polymerBond: PolymerBond, flip = false) {
let angleRadians = 0;
if (flip) {
Expand Down
Loading