Skip to content

Commit

Permalink
#4823 - In sequence mode, each press adds two characters and when del…
Browse files Browse the repository at this point in the history
…eted, also removes two (#4825)

- added removing keydown subscription after editor destroy
  • Loading branch information
rrodionov91 committed Jun 10, 2024
1 parent 710b3c4 commit 5a0fd66
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/ketcher-core/src/application/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class CoreEditor {
private hotKeyEventHandler: (event: unknown) => void = () => {};
private copyEventHandler: (event: ClipboardEvent) => void = () => {};
private pasteEventHandler: (event: ClipboardEvent) => void = () => {};
private keydownEventHandler: (event: KeyboardEvent) => void = () => {};

constructor({ theme, canvas }: ICoreEditorConstructorParams) {
this.theme = theme;
Expand Down Expand Up @@ -163,9 +164,11 @@ export class CoreEditor {

private setupKeyboardEvents() {
this.setupHotKeysEvents();
document.addEventListener('keydown', async (event: KeyboardEvent) => {
this.keydownEventHandler = async (event: KeyboardEvent) => {
await this.mode.onKeyDown(event);
});
};

document.addEventListener('keydown', this.keydownEventHandler);
}

private setupCopyPasteEvent() {
Expand Down Expand Up @@ -386,6 +389,7 @@ export class CoreEditor {
document.removeEventListener('keydown', this.hotKeyEventHandler);
document.removeEventListener('copy', this.copyEventHandler);
document.removeEventListener('paste', this.pasteEventHandler);
document.removeEventListener('keydown', this.keydownEventHandler);
}

get trackedDomEvents() {
Expand Down

0 comments on commit 5a0fd66

Please sign in to comment.