Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function initKeymap(window, dispatch) {
registerListeners(window, dispatch);
const document = window.document;
const keymaps = new KeymapManager();
keymaps.defaultTarget = document.body;
document.addEventListener('keydown', event => keymaps.handleKeyboardEvent(event));
// Add the keymap files, can also be specified as directories
keymaps.add('/default-keymap', require('../../../static/default-map.json'));
// keymaps.loadKeymap('/path/to/keymap-file.json');
}
import { KeymapManager, ICompleteMatchEvent } from "atom-keymap";
var manager = new KeymapManager();
manager.add('some/unique/path', {
'.workspace': {
'ctrl-x': 'package:do-something',
'ctrl-y': 'package:do-something-else'
},
'.mini.editor': {
'enter': 'core:confirm'
}
});
manager.onDidMatchBinding((event: ICompleteMatchEvent): void => {
console.log(event.binding.command);
})
manager.destroy();
it('dispatches the event via the KeymapManager and CommandRegistry', () => {
const dispatchedCommands = [];
atom.commands.onWillDispatch(command => dispatchedCommands.push(command));
atom.commands.add('*', { 'foo-command': () => {} });
atom.keymaps.add('source-name', { '*': { x: 'foo-command' } });
const event = KeymapManager.buildKeydownEvent('x', {
target: document.createElement('div')
});
document.dispatchEvent(event);
expect(dispatchedCommands.length).toBe(1);
expect(dispatchedCommands[0].type).toBe('foo-command');
}));
const bind = el => {
keymaps = new KeymapManager();
keymaps.defaultTarget = el;
keymaps.loadKeymap(`${config.keymapsFolder}/linux.json`);
document.addEventListener('keydown', eventListener);
};