Skip to content

Commit

Permalink
feat: add default key formator for shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Dec 13, 2019
1 parent 3339199 commit 86af678
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/x6/src/handler/keyboard/handler.ts
Expand Up @@ -18,6 +18,16 @@ export class KeyboardHandler extends BaseHandler {
this.mousetrap = new Mousetrap(this.target as Element, this)
}

enable() {
this.graph.options.keyboard.enabled = true
super.enable()
}

disable() {
this.graph.options.keyboard.enabled = false
super.disable()
}

bind(
keys: string | string[],
callback: KeyboardHandler.Handler,
Expand All @@ -31,7 +41,15 @@ export class KeyboardHandler extends BaseHandler {
}

private getKeys(keys: string | string[]) {
return (Array.isArray(keys) ? keys : [keys]).map(this.formatkey)
return (Array.isArray(keys) ? keys : [keys])
.map(key =>
key
.toLowerCase()
.replace(/\s/g, '')
.replace('delete', 'backspace')
.replace('cmd', 'command'),
)
.map(this.formatkey)
}

protected isGraphEvent(e: KeyboardEvent) {
Expand Down

0 comments on commit 86af678

Please sign in to comment.