Skip to content

Commit 066fed4

Browse files
authored
Merge pull request inveniosoftware-contrib#418 from harunurhan/fix-shortcuts
fix shorcuts when there is no custom shortcuts config
2 parents 7e742dc + e4881c3 commit 066fed4

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/shared/directives/shortcuts.directive.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,25 @@ export class ShortcutsDirective implements OnDestroy, OnChanges {
113113

114114
ngOnChanges(changes: SimpleChanges) {
115115
const customShortcutKeysChange = changes['shortcuts'];
116-
if (customShortcutKeysChange && this.shortcuts) {
117-
Object.keys(this.actionNameToShortcut).forEach(actionName => {
118-
const shortcut = this.actionNameToShortcut[actionName];
119-
if (this.shortcuts[actionName]) {
120-
shortcut.key = this.shortcuts[actionName];
121-
}
122-
this.mousetrap.bind(shortcut.key, shortcut.action);
123-
});
116+
if (customShortcutKeysChange) {
117+
const actionNames = Object.keys(this.actionNameToShortcut);
118+
// if custom shortcut keys are set
119+
if (this.shortcuts) {
120+
actionNames.forEach(actionName => {
121+
const shortcut = this.actionNameToShortcut[actionName];
122+
if (this.shortcuts[actionName]) {
123+
// override shortcut key
124+
shortcut.key = this.shortcuts[actionName];
125+
}
126+
this.mousetrap.bind(shortcut.key, shortcut.action);
127+
});
128+
} else {
129+
actionNames.forEach(actionName => {
130+
const shortcut = this.actionNameToShortcut[actionName];
131+
this.mousetrap.bind(shortcut.key, shortcut.action);
132+
});
133+
}
134+
124135
}
125136
}
126137

0 commit comments

Comments
 (0)