Skip to content

Commit

Permalink
#4730 - System doubles number of pasted monomers after switching from…
Browse files Browse the repository at this point in the history
… flex to sequence (#4742)

- added removing of copy/paste event listeners during switching between micro/macro modes
  • Loading branch information
rrodionov91 authored Jun 4, 2024
1 parent d00edaa commit e3de348
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/ketcher-core/src/application/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export class CoreEditor {
public sequenceTypeEnterMode = SequenceType.RNA;
private micromoleculesEditor: Editor;
private hotKeyEventHandler: (event: unknown) => void = () => {};
private copyEventHandler: (event: ClipboardEvent) => void = () => {};
private pasteEventHandler: (event: ClipboardEvent) => void = () => {};

constructor({ theme, canvas }: ICoreEditorConstructorParams) {
this.theme = theme;
Expand Down Expand Up @@ -167,12 +169,14 @@ export class CoreEditor {
}

private setupCopyPasteEvent() {
document.addEventListener('copy', (event: ClipboardEvent) => {
this.copyEventHandler = (event: ClipboardEvent) => {
this.mode.onCopy(event);
});
document.addEventListener('paste', (event: ClipboardEvent) => {
};
this.pasteEventHandler = (event: ClipboardEvent) => {
this.mode.onPaste(event);
});
};
document.addEventListener('copy', this.copyEventHandler);
document.addEventListener('paste', this.pasteEventHandler);
}

private setupHotKeysEvents() {
Expand Down Expand Up @@ -380,6 +384,8 @@ export class CoreEditor {
this.events[eventName].handlers = [];
}
document.removeEventListener('keydown', this.hotKeyEventHandler);
document.removeEventListener('copy', this.copyEventHandler);
document.removeEventListener('paste', this.pasteEventHandler);
}

get trackedDomEvents() {
Expand Down

0 comments on commit e3de348

Please sign in to comment.