// Hide <textarea> elements. We only want to see the CodeMirror 3-way
// editor. If JavaScript is disabled, the user will see the <textarea>
// but not the CodeMirror editor.
document.querySelectorAll('.three_way textarea').forEach(textarea => {
    textarea.style.display = 'none';
})

var editor_type      = document.getElementById("editor_script").getAttribute("data-type");
var textarea_current = document.getElementById('current_content');
var textarea_content = document.getElementById('content');
var textarea_changed = document.getElementById('changed_content');

var editor = CodeMirror.MergeView(
    document.getElementById('three_way_editor'),
    {
        // CodeMirror
        mode: (editor_type == 'facts' ? 'turtle' : 'markdown'),
        theme: 'default',
        lineNumbers: true,
        lineWrapping: true,
        scrollbarStyle: null,
        undoDepth: 1000,
        autofocus: true,
        spellcheck: false,
        autocapitalize: false,
        
        // Merge addon
        value: textarea_content.value,
        origLeft: textarea_current.value,
        origRight: textarea_changed.value,
        highlightDifferences: true,
        connect: null, // 'align',
        collapseIdentical: true
    });

// When the form is submitted, we copy the CodeMirror content to the
// hidden <textarea>
document.getElementById('form_content').addEventListener('submit', (event) => {
    textarea_content.value = editor.editor().getValue();
});
    
