Skip to content

Instantly share code, notes, and snippets.

@tovic tovic/codemirror-0.js
Last active Feb 15, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.