hi all.
I think I have a question I was not able to find already answered (something near is this thing Separate keyboard shortcuts for canvas and selected elements - #2 by nikku)
so what I would like to do : we have custom build of bpmn-js + some tweaks like custom render, custom contextpad and custom palette.
I would like to have custom keyboard events that I can hook on a page I will host my build of bpmn-js and I could listen to them via eventBus since IMO that is the correct thing to do.
I have changed a bit the sample from above and for me this code works :
import KeyboardBindings from 'bpmn-js/lib/features/keyboard/BpmnKeyboardBindings';
class CustomKeyboardBindings extends KeyboardBindings {
constructor(injector) {
super(injector);
injector.invoke(KeyboardBindings, this);
}
registerBindings(keyboard, editorActions) {
// register another listener with a higher priority so it's called first
keyboard.addListener(10000, context => {
const event = context.keyEvent;
// check whether the key pressed is 'o' + CTRL
if (event.ctrlKey && keyboard.isKey(['o'], event)) {
event.preventDefault();
keyboard._eventBus.fire('custom.openDiagramEvent', event);
}
// check whether the key pressed is 's' + CTRL
if (event.ctrlKey && keyboard.isKey(['s'], event)) {
event.preventDefault();
keyboard._eventBus.fire('custom.saveDiagramEvent', event);
}
});
}
}
export default {
__init__: ['customKeyboard'],
customKeyboard: ['type', CustomKeyboardBindings],
}
in the JS on the page where I listen to events I can hook them like this :
//listens for CTRL + o triggered via eventBus
eventBus.on('custom.openDiagramEvent', function (event: Event) {
diagramsClicked();
});
my concern in that in the sample there was this signature
public registerBindings(keyboard, editorActions, eventBus) {
which never worked for me (the eventBus prop was never passed from caller) and I had to use the
keyboard._eventBus.fire('custom.openDiagramEvent', event);
which is IMO using private prop of the keyboard obj.
any idea on how the hooking to custom event should look like? thx