-
Notifications
You must be signed in to change notification settings - Fork 183
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
Macro: #3713 - Hot keys for toolbar buttons are not implemented in Macromoleculas view #3836
Changes from all commits
a3fb4fa
90befb0
68d07da
9707432
86b71ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ZoomTool from './tools/Zoom'; | |
import { Coordinates } from './shared/coordinates'; | ||
import { | ||
editorEvents, | ||
hotkeysConfiguration, | ||
renderersEvents, | ||
resetEditorEvents, | ||
} from 'application/editor/editorEvents'; | ||
|
@@ -26,6 +27,7 @@ import { MacromoleculesConverter } from 'application/editor/MacromoleculesConver | |
import { BaseMonomer } from 'domain/entities/BaseMonomer'; | ||
import { ketcherProvider } from 'application/utils'; | ||
import { SnakeMode } from './modes/internal'; | ||
import { initHotKeys, keyNorm } from '../../utilities/keynorm'; | ||
|
||
interface ICoreEditorConstructorParams { | ||
theme; | ||
|
@@ -51,6 +53,7 @@ export class CoreEditor { | |
// private lastEvent: Event | undefined; | ||
private tool?: Tool | BaseTool; | ||
private micromoleculesEditor: Editor; | ||
private hotKeyEventHandler: (event: unknown) => void = () => {}; | ||
|
||
constructor({ theme, canvas }: ICoreEditorConstructorParams) { | ||
this.theme = theme; | ||
|
@@ -61,6 +64,7 @@ export class CoreEditor { | |
this.renderersContainer = new RenderersManager({ theme }); | ||
this.drawingEntitiesManager = new DrawingEntitiesManager(); | ||
this.domEventSetup(); | ||
this.setupHotKeysEvents(); | ||
this.canvasOffset = this.canvas.getBoundingClientRect(); | ||
this.zoomTool = ZoomTool.initInstance(this.drawingEntitiesManager); | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
|
@@ -74,6 +78,22 @@ export class CoreEditor { | |
return editor; | ||
} | ||
|
||
private handleHotKeyEvents(event) { | ||
const keySettings = hotkeysConfiguration; | ||
const hotKeys = initHotKeys(keySettings); | ||
const shortcutKey = keyNorm.lookup(hotKeys, event); | ||
|
||
if (keySettings[shortcutKey] && keySettings[shortcutKey].handler) { | ||
keySettings[shortcutKey].handler(this); | ||
event.preventDefault(); | ||
} | ||
} | ||
|
||
setupHotKeysEvents() { | ||
this.hotKeyEventHandler = (event) => this.handleHotKeyEvents(event); | ||
document.addEventListener('keydown', this.hotKeyEventHandler); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just simply?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, because we need to bind 'this' to hotKeyEventHandler method. And this.hotKeyEventHandler.bind(this) also didn't work because it returns another function and it did not clear event listener in this case. |
||
} | ||
|
||
private subscribeEvents() { | ||
this.events.selectMonomer.add((monomer) => this.onSelectMonomer(monomer)); | ||
this.events.selectPreset.add((preset) => this.onSelectRNAPreset(preset)); | ||
|
@@ -104,7 +124,7 @@ export class CoreEditor { | |
} | ||
} | ||
|
||
private onSelectTool(tool: string) { | ||
public onSelectTool(tool: string) { | ||
this.selectTool(tool); | ||
} | ||
|
||
|
@@ -140,7 +160,7 @@ export class CoreEditor { | |
this.renderersContainer.update(command); | ||
} | ||
|
||
private onSelectHistory(name: HistoryOperationType) { | ||
public onSelectHistory(name: HistoryOperationType) { | ||
const history = new EditorHistory(this); | ||
if (name === 'undo') { | ||
history.undo(); | ||
|
@@ -164,6 +184,7 @@ export class CoreEditor { | |
for (const eventName in this.events) { | ||
this.events[eventName].handlers = []; | ||
} | ||
document.removeEventListener('keydown', this.hotKeyEventHandler); | ||
} | ||
|
||
get trackedDomEvents() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify