How to paste source code from IDE to posts directly?

Have you tried another editor?

You could try CKEeditor, according to some it does not mess with the code indents.

https://wordpress.org/plugins/ckeditor-for-wordpress/