Document command handler

Hi,

The command handler only acts on input commands when the canvas has focus. I would like to propagate commands to the command handler even if the canvas does not have focus, e.g. when another html element is selected or clicked last. Would this be possible? I could add event listeners to the document to catch keyboard events and then send these to the diagram.commandHandler I suppose? What would be the best way of doing this? Or would there be another preferred way?

Thanks!

In apps I have implemented I have chosen to call Diagram.focus for those events on other elements where I would then expect the user to be “focused” on the diagram. That way no delegation of events is required.

But yes, “forwarding” events is quite possible for keyboard events and for other events too.

Thanks for your reply Walter. I discussed this with the team and I think the forwarding option would work better for us since the total app is build around the diagram so we always want to undo an operation via the CommandHandler if an arbitrary element has focus.

What would your approach be of forwarding all keyboard commands to the CommandHandler of gojs? I could forward all events manually but I isn’t there a more low-level approach of forwarding all document KeyboardEvents?

Thanks again!

I see that calling diagram.focus already forwards the commands. So that would work already. Thanks!