Skip to content
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

Fire keyup events for ActionEventBus.keys on document blur #920

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react-canvas-core/src/Toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Toolkit {

public static closest(element: Element, selector: string) {
if (!Element.prototype.closest) {
Element.prototype.closest = function(s) {
Element.prototype.closest = function (s) {
var el = this;

do {
Expand Down
6 changes: 6 additions & 0 deletions packages/react-canvas-core/src/core-actions/ActionEventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ export class ActionEventBus {
action.options.fire(actionEvent as any);
}
}

clearKeys() {
_.forEach(Object.keys(this.keys), (key) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont need the Object.keys, _.forEach will give the key as the second param in the callback

document.dispatchEvent(new KeyboardEvent('keyup', { key: key }));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class CanvasWidget extends React.Component<DiagramProps> {
ref: React.RefObject<HTMLDivElement>;
keyUp: any;
keyDown: any;
blur: any;
canvasListener: any;

constructor(props: DiagramProps) {
Expand Down Expand Up @@ -65,9 +66,13 @@ export class CanvasWidget extends React.Component<DiagramProps> {
this.keyUp = (event) => {
this.props.engine.getActionEventBus().fireAction({ event });
};
this.blur = () => {
this.props.engine.getActionEventBus().clearKeys();
};

document.addEventListener('keyup', this.keyUp);
document.addEventListener('keydown', this.keyDown);
document.addEventListener('blur', this.blur);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see other comments, also this needs to be deregistered in unmount

this.registerCanvas();
}

Expand Down