Skip to content

Instantly share code, notes, and snippets.

@taufik-nurrohman
Last active February 15, 2018 16:53
Show Gist options
  • Save taufik-nurrohman/f1f21602e6b682ad78d6140f505e14f3 to your computer and use it in GitHub Desktop.
Save taufik-nurrohman/f1f21602e6b682ad78d6140f505e14f3 to your computer and use it in GitHub Desktop.
CodeMirror Hotkeys for Bold and Italic
editor.addKeyMap({
// bold
'Ctrl-B': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 2) === '**' && s.slice(-2) === '**';
cm.replaceSelection(t ? s.slice(2, -2) : '**' + s + '**', 'around');
},
// italic
'Ctrl-I': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 1) === '_' && s.slice(-1) === '_';
cm.replaceSelection(t ? s.slice(1, -1) : '_' + s + '_', 'around');
},
// code
'Ctrl-K': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 1) === '`' && s.slice(-1) === '`';
cm.replaceSelection(t ? s.slice(1, -1) : '`' + s + '`', 'around');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment