KeybindingSet: fix missing item type (#106428)

* KeybindingSet: fix missing item type

* KeybindingSet: pass default value to bind call
This commit is contained in:
Matias Chomicki
2025-06-09 19:08:52 +02:00
committed by GitHub
parent 08168a33e9
commit 7ee6b24872
2 changed files with 49 additions and 2 deletions
@@ -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');
});
});
+5 -2
View File
@@ -24,9 +24,12 @@ export class KeybindingSet {
evt.returnValue = false;
item.onTrigger();
},
'keydown'
item.type ?? 'keydown'
);
this._binds.push(item);
this._binds.push({
...item,
type: item.type ?? 'keydown',
});
}
removeAll() {