Skip to content

Commit

Permalink
#2849 – When zoom out or zoom in, atoms and templates are located not…
Browse files Browse the repository at this point in the history
… under the mouse cursor (#3182)
  • Loading branch information
Nitvex authored Aug 25, 2023
1 parent 893e9e6 commit 4a37ded
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/ketcher-react/src/script/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ function updateLastCursorPosition(editor: Editor, event) {
editor.render.clientArea.getBoundingClientRect();

editor.lastCursorPosition = {
x: event.pageX - clientAreaBoundingBox.x,
y: event.pageY - clientAreaBoundingBox.y,
x: event.clientX - clientAreaBoundingBox.x,
y: event.clientY - clientAreaBoundingBox.y,
};
}
}
Expand Down
12 changes: 10 additions & 2 deletions packages/ketcher-react/src/script/editor/HoverIcon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ElementLabel, AtomColor } from 'ketcher-core';
import { type ElementLabel, type AtomColor, Vec2 } from 'ketcher-core';
import Editor from './Editor';

const HOVER_ICON_OPACITY = 0.7;
Expand Down Expand Up @@ -76,8 +76,16 @@ export class HoverIcon {
}

updatePosition() {
const render = this.editor.render;
const { x, y } = this.editor.lastCursorPosition;
this.element.attr({ x, y });
const currentPosition = new Vec2(x, y);
const scrollPosition = render.scrollPos();
const zoom = render.options.zoom;
const newPosition = currentPosition.add(scrollPosition).scaled(1 / zoom);
this.element.attr({
x: newPosition.x,
y: newPosition.y,
});
}

show() {
Expand Down

0 comments on commit 4a37ded

Please sign in to comment.