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

event.keyCode deprecated #854

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 2 additions & 9 deletions diagrams-demo-gallery/demos/demo-custom-action/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ import createEngine, { DiagramModel, DefaultNodeModel, DefaultLinkModel } from '
import { CanvasWidget, Action, ActionEvent, InputType } from '@projectstorm/react-canvas-core';
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';

interface CustomDeleteItemsActionOptions {
keyCodes?: number[];
Copy link
Member

Choose a reason for hiding this comment

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

I think we should still allow the user to specify the name of the keys. For example, it would be nice if they could specify Del, Backspace etc..

Copy link
Author

Choose a reason for hiding this comment

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

Looks like you are right =)
But this feature will be disabled soon (not so soon, but still..)

I just though that codebase should be consistent with latest tendentions of the goodness of the code accepted in the community =)

Thanks for feedback!

}

/**
* Deletes all selected items, but asks for confirmation first
*/
class CustomDeleteItemsAction extends Action {
constructor(options: CustomDeleteItemsActionOptions = {}) {
options = {
keyCodes: [46, 8],
...options
};
constructor() {
super({
type: InputType.KEY_DOWN,
fire: (event: ActionEvent<React.KeyboardEvent>) => {
if (options.keyCodes.indexOf(event.event.keyCode) !== -1) {
if (event.event.code === 'Delete') {
const selectedEntities = this.engine.getModel().getSelectedEntities();
if (selectedEntities.length > 0) {
const confirm = window.confirm('Are you sure you want to delete?');
Expand Down