Skip to content

Instantly share code, notes, and snippets.

@sergiopvilar
Created October 2, 2017 21:49
Show Gist options
  • Save sergiopvilar/772f9bb39d0cc46b35e4eaacb389d736 to your computer and use it in GitHub Desktop.
Save sergiopvilar/772f9bb39d0cc46b35e4eaacb389d736 to your computer and use it in GitHub Desktop.
Translate DVORAK hotkeys to QWERTY in Atom
atom.keymaps.addKeystrokeResolver(({keystroke, event}) => {
var qKeys = "q w e r t y u i o p [ ] a s d f g h j k l ; ' z x c v b n m , . /".split(' ')
, dvorakKeys = "' , . p y f g c r l / = a o e u i d h t n s - ; q j k x b m w v z".split(' ')
, key = keystroke
, replaced = [];
if(event.type == 'keydown' && event.metaKey && event.key !== 'Meta' && keystroke.startsWith('cmd-')) {
for(var i in dvorakKeys) {
if(
key.indexOf('-' + dvorakKeys[i]) > -1 &&
replaced.indexOf(dvorakKeys[i]) == -1 &&
(key.endsWith('-' + dvorakKeys[i]) || key.indexOf('-'+dvorakKeys[i]+'-') > -1)
) {
key = key.replace('-' + dvorakKeys[i], '-' + qKeys[i]);
replaced.push(qKeys[i]);
}
}
if(keystroke !== key) console.log(keystroke + ' translated to ' + key);
return key;
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment