When pasting a large chunk of text into the markdown editor, it often would be useful to automatically wrap it with ~~~~ or indent it. People who paste code snippets or log lines would benefit from this, especially if they are not familiar with markdown and don't realize it needs to be in a code block to avoid __foo__ from getting formatted etc. I think this would help alleviate problems expressed in https://sourceforge.net/p/forge/feature-requests/134/
However, that won't be appropriate all the time, since some people could paste large amounts of regular text or even markdown formatting (e.g. restructuring a wiki page). Turning it into a code block won't be helpful. We'll need some sort of UI to make this work well. I am thinking that we show a notification after it happens, and tell the user how they can click the code snippet button to undo it. We can also save a cookie/sessionStorage setting to not do it again.
Here's an autoindent snippet proof-of-concept:
cm = editor.codemirror;
// based on https://github.com/codemirror/CodeMirror/issues/2120
cm.on("change", function(cm, change) {
if (change.origin != "paste" || change.text.length < 2) {
return;
}
var spaces = cm.options.tabSize;
cm.operation(function() {
for (var line = change.from.line, end = CodeMirror.changeEnd(change).line; line <= end; ++line) {
cm.indentLine(line, spaces);
}
});
});