I’m using wp_editor
to add wysiwyg fields to admin edit screens. Each wysiwyg lives within a draggable meta box. Since TinyMCE has issues with dragging, I’m using the following code:
// on the dragstart event
tinyMCE.execCommand('mceRemoveControl', false, the_editor_id);
// on the dragstop event
tinyMCE.execCommand('mceAddControl', false, the_editor_id);
The problem is that, when mceAddControl
is fired, all newlines and linebreaks are stripped from the text. Has anyone been able to solve this issue?
Before dragstart:
After dragstop:
It turns out that TinyMCE has it’s own
autop
setting, so if you kill it before the sort and then put it back you should be good to go!Check out the
autop
setting handling in this snippet:Snippet pulled from my WordPress plugin, Attachments: https://github.com/jchristopher/attachments/blob/3.3.2/classes/fields/class.field.wysiwyg.php