CodeMirror has its own inputRead event, so you can do this:
editor.on('inputRead', function(cm, event) {
if (event.origin == 'paste') {
console.log(event.text);
var text = event.text[0];
var new_text = '['+text+']';
cm.refresh();
cm.replaceRange(new_text, event.from, {line: event.from.line, ch: event.from.ch + text.length});
}
});
: "cut", "copy" "paste" (http://codemirror.net/doc/manual.html#events), :
editor.on('paste', function(cm, event) { ... } );
Andavtage - , event.preventDefault(); .
- . . clipboard.js
codemirror API , ?. , ( , ZeroClipboard - -), !
new Clipboard('.btn-copy', {
text: function(trigger) {
var text = editor.getValue();
return text.replace(/\s+/g,' ');
}
});
editor.on('copy', function(cm, event) {
$('.btn-copy').click();
event.preventDefault();
});