Skip to content

Commit

Permalink
#3129 - Full template preview following mouse cursor 2
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinEpam23 committed Sep 6, 2023
1 parent 72f26c9 commit d54811b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
***************************************************************************/

import { Atom, Bond, SGroup, Struct, Vec2 } from 'domain/entities';
import { AtomAdd, BondAdd, BondAttr, CalcImplicitH } from '../operations';
import { AtomAdd, AtomAttr, BondAdd, BondAttr, CalcImplicitH } from '../operations';
import { atomForNewBond, atomGetAttr } from './utils';
import { fromAtomsAttrs, mergeSgroups } from './atom';
import { fromBondStereoUpdate, fromBondsAttrs, fromBondAddition } from './bond';
Expand Down Expand Up @@ -144,6 +144,7 @@ export function fromTemplateOnAtom(
action.mergeWith(fromAtomsAttrs(restruct, aid1, attrs, true));
map.set(id, aid1);
pasteItems.atoms.push(aid1);
new AtomAttr(aid1, 'isPreview', isPreview).perform(restruct);
} else {
const v = Vec2.diff(a.pp, xy0).rotate(delta).add(atom.pp);

Expand All @@ -153,8 +154,10 @@ export function fromTemplateOnAtom(
action.addOp(operation);
map.set(id, operation.data.aid);
pasteItems.atoms.push(operation.data.aid);
new AtomAttr(operation.data.aid, 'isPreview', isPreview).perform(
restruct,
);
}
// new AtomAttr(id, 'isPreview', isPreview).perform(restruct);
});

if (!isTmplSingleGroup) mergeSgroups(action, restruct, pasteItems.atoms, aid);
Expand Down
3 changes: 3 additions & 0 deletions packages/ketcher-react/src/script/editor/shared/closest.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ function findClosestAtom(restruct, pos, skip, minDist) {
) {
return null;
}
if (atom.a.isPreview && !atom.hover) {
return;
}
if (aid === skipId) return;

const dist = Vec2.dist(pos, atom.a.pp);
Expand Down
10 changes: 8 additions & 2 deletions packages/ketcher-react/src/script/editor/tool/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
Bond,
fromMultipleMove,
BondAttr,
AtomAttr,
} from 'ketcher-core';
import Editor from '../Editor';
import { getGroupIdsFromItemArrays } from './helper/getGroupIdsFromItems';
Expand Down Expand Up @@ -599,8 +600,13 @@ class TemplateTool implements Tool {
);
action = result[0];
pasteItems = result[1];
for (const bid of pasteItems.bonds || []) {
new BondAttr(bid, 'isPreview', false).perform(
for (const bondId of pasteItems.bonds || []) {
new BondAttr(bondId, 'isPreview', false).perform(
this.editor.render.ctab,
);
}
for (const atomId of pasteItems.atoms || []) {
new AtomAttr(atomId, 'isPreview', false).perform(
this.editor.render.ctab,
);
}
Expand Down

0 comments on commit d54811b

Please sign in to comment.