KeybindingSet: fix missing item type (#106428)
* KeybindingSet: fix missing item type * KeybindingSet: pass default value to bind call
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
import { KeybindingSet } from './KeybindingSet';
|
||||||
|
import { mousetrap } from './mousetrap';
|
||||||
|
|
||||||
|
jest.mock('./mousetrap');
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
jest.unmock('./mousetrap');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('KeybindingSet', () => {
|
||||||
|
let keyBindingSet: KeybindingSet;
|
||||||
|
beforeEach(() => {
|
||||||
|
keyBindingSet = new KeybindingSet();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Binds and unbinds keys', () => {
|
||||||
|
keyBindingSet.addBinding({
|
||||||
|
key: 'a b',
|
||||||
|
onTrigger: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mousetrap.bind).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mousetrap.bind).toHaveBeenCalledWith('a b', expect.any(Function), 'keydown');
|
||||||
|
|
||||||
|
keyBindingSet.removeAll();
|
||||||
|
|
||||||
|
expect(mousetrap.unbind).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mousetrap.unbind).toHaveBeenCalledWith('a b', 'keydown');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Binds and unbinds keys of a certain type', () => {
|
||||||
|
keyBindingSet.addBinding({
|
||||||
|
key: 'a b',
|
||||||
|
onTrigger: () => {},
|
||||||
|
type: 'keypress',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mousetrap.bind).toHaveBeenCalledWith('a b', expect.any(Function), 'keypress');
|
||||||
|
|
||||||
|
keyBindingSet.removeAll();
|
||||||
|
|
||||||
|
expect(mousetrap.unbind).toHaveBeenCalledWith('a b', 'keypress');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -24,9 +24,12 @@ export class KeybindingSet {
|
|||||||
evt.returnValue = false;
|
evt.returnValue = false;
|
||||||
item.onTrigger();
|
item.onTrigger();
|
||||||
},
|
},
|
||||||
'keydown'
|
item.type ?? 'keydown'
|
||||||
);
|
);
|
||||||
this._binds.push(item);
|
this._binds.push({
|
||||||
|
...item,
|
||||||
|
type: item.type ?? 'keydown',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAll() {
|
removeAll() {
|
||||||
|
|||||||
Reference in New Issue
Block a user