我试着同时这两个,但由于tinyMCE上的一些丢失的回调/事件,这是我最好的。 ACE中的内容仅在tinyMCE模糊后更新。目前还没有任何直接的输入事件:
Fiddle forked
代码:
var editor = ace.edit("edit");
var textarea = $('textarea[name="test"]');
editor.getSession().setValue(textarea.val());
editor.getSession().on('change', function(){
textarea.val(editor.getSession().getValue());
// copy ace to tinyMCE
tinymce.get('test').setContent(editor.getSession().getValue());
});
editor.setTheme("https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.2/theme-terminal.js");
editor.getSession().setMode("https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.2/mode-html.js");
tinymce.init({
selector: ".test",
relative_urls: false,
apply_source_formatting : true,
setup : function(ed) {
ed.on('change', function(e) {
// copy tinyMCE to textarea
textarea.val(tinymce.activeEditor.getContent({format : 'raw'}));
// copy tinyMCE to ace
editor.getSession().setValue(
tinymce.activeEditor.getContent({format : 'raw'})
);
});
}
});
TinyMCE有一个代码视图'tinymce.init({插件: “代码”});' - 为什么添加ACE进混合和复杂的东西? – staypuftman
为了能见度目的,我将两者分开。代码视图与tinymce不同的部分使用。这就是为什么我选择了ace编辑器,而且它们比tinymce – Lynx