angular-hotkeys
angular-hotkeys copied to clipboard
Cannot add multiple callbacks to the same combo.
Not sure if feature or bug, consider this script.
app.controller('ParentCtrl', function($scope, hotkeys) {
hotkeys.bindTo($scope).add({
combo: 'enter',
allowIn: ['INPUT', 'TEXTAREA'],
callback: function($evt) {
$evt.preventDefault();
logKeypress($evt);
}
});
});
app.controller('ChildCtrl1', function($scope, hotkeys) {
hotkeys.bindTo($scope).add({
combo: 'enter',
allowIn: ['INPUT', 'TEXTAREA'],
callback: function($evt) {
// Do something else ...
}
});
});
I wanted to override the default browser submit action and add custom actions for the ENTER key for each ng-view
controller, but when ChildCtrl1
is in action, callback in ParentCtrl
won't fire.
Can we modify this line hotkeys.js:1469 to allow multiple bindings?
I tried to comment it out and it works on Hotkey.add()
, while bindTo()
already took care of unbinding with _del()
, it turns out to be kind of a Mousetrap
design flaw because Mousetrap.unbind()
does not support a callback
argument.
Similar problem, but for other reasons what does not work anylonger since 1.6.
I'm trying to add behaviour when there is the ctrl key pressed, unfortunately it does not work in every browser, therefore the need to add multiple duplicate combos.
hotKeyObj.add({
combo: 'ctrl',
action: 'keypress',
callback: function (event, hotkey) {
keyStatusMap.ctrlPressed = true;
}
}).add({
combo: 'ctrl',
action: 'keydown',
description: gettextCatalog.getString('Hightlight mode'),
callback: function (event, hotkey) {
keyStatusMap.ctrlPressed = true;
}
}).add({
combo: 'ctrl',
action: 'keyup',
callback: function (event, hotkey) {
keyStatusMap.ctrlPressed = false;
}
});
Having the same problem as @ceilino described. I have assigned different callbacks to keyup and keydown of the same combo, and it no longer works.
... and this is the reason: https://github.com/chieffancypants/angular-hotkeys/commit/a3b4b4c233abca579d186543b46c011580a42f65#diff-30ea385d3977d7c1a62acdb050ea857aR338
+1
+1
Some great people made a PR on a dependency mousetrap-js/mousetrap/pull/12, we can make use of the new parameters here.
+1