Last active
February 15, 2018 16:53
-
-
Save taufik-nurrohman/f1f21602e6b682ad78d6140f505e14f3 to your computer and use it in GitHub Desktop.
CodeMirror Hotkeys for Bold and Italic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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