<commit_before><!DOCTYPE html>
<html>
<head>
<script>

/**
 * source.html
 *
 * Copyright 2013-2014 Web Power, www.webpower.nl
 * @author <NAME>
 */

// Global vars:
var tinymce,     // Reference to TinyMCE
	editor,      // Reference to TinyMCE editor
	codemirror,  // CodeMirror instance
	chr = 0,     // Unused utf-8 character, placeholder for cursor
	isMac = /macintosh|mac os/i.test(navigator.userAgent),
	CMsettings;  // CodeMirror settings

function inArray(key, arr)
{
	"use strict";
	arr = '|' + arr.join('|') + '|';
	return arr.indexOf('|'+key+'|') != -1;
}

(function()
{// Initialise (before load)
	"use strict";

	tinymce = parent.tinymce;
	editor = tinymce.activeEditor;
	var i, userSettings = editor.settings.codemirror ? editor.settings.codemirror : null;
	CMsettings = {
		path: userSettings.path || 'CodeMirror',
		indentOnInit: userSettings.indentOnInit || false,
		config: {// Default config
			mode: 'htmlmixed',
			lineNumbers: true,
			lineWrapping: true,
			indentUnit: 1,
			tabSize: 1,
			matchBrackets: true,
			styleActiveLine: true
		},
		jsFiles: [// Default JS files
			'lib/codemirror.js',
			'addon/edit/matchbrackets.js',
			'mode/xml/xml.js',
			'mode/javascript/javascript.js',
			'mode/css/css.js',
			'mode/htmlmixed/htmlmixed.js',
			'addon/dialog/dialog.js',
			'addon/search/searchcursor.js',
			'addon/search/search.js',
			'addon/selection/active-line.js'
		],
		cssFiles: [// Default CSS files
			'lib/codemirror.css',
			'addon/dialog/dialog.css'
		]
	};

	// Merge config
	for (i in userSettings.config) {
		CMsettings.config[i] = userSettings.config[i];
	}
	
	// Merge jsFiles
	for (i in userSettings.jsFiles) {
		if (!inArray(userSettings.jsFiles[i], CMsettings.jsFiles)) {
			CMsettings.jsFiles.push(userSettings.jsFiles[i]);
		}
	}

	// Merge cssFiles
	for (i in userSettings.cssFiles) {
		if (!inArray(userSettings.cssFiles[i], CMsettings.cssFiles)) {
			CMsettings.cssFiles.push(userSettings.cssFiles[i]);
		}
	}

	// Add trailing slash to path
	if (!/\/$/.test(CMsettings.path)) {
		CMsettings.path += '/';
	}

	// Write stylesheets
	for (i = 0; i < CMsettings.cssFiles.length; i++) {
		document.write('<li'+'nk rel="stylesheet" type="text/css" href="' + CMsettings.path + CMsettings.cssFiles[i] + '" />');
	}

	// Write JS source files
	for (i = 0; i < CMsettings.jsFiles.length; i++) {
		document.write('<scr'+'ipt type="text/javascript" src="' + CMsettings.path + CMsettings.jsFiles[i] + '"></scr'+'ipt>');
	}

	window.onload = start;
}());

function start()
{// Initialise (on load)
	"use strict";

	if (typeof(window.CodeMirror) !== 'function') {
		alert('CodeMirror not found in "' + CMsettings.path + '", aborting...');
		return;
	}

	// Create legend for keyboard shortcuts for find & replace:
	var head = parent.document.querySelectorAll('.mce-foot')[0],
		div = parent.document.createElement('div'),
		td1 = '<td style="font-size:11px;background:#777;color:#fff;padding:0 4px">',
		td2 = '<td style="font-size:11px;padding-right:5px">';
	div.innerHTML = '<table cellspacing="0" cellpadding="0" style="border-spacing:4px"><tr>' + td1 + (isMac ? '&#8984;-F' : 'Ctrl-F</td>') + td2 + tinymce.translate('Start search') + '</td>' + td1 + (isMac ? '&#8984;-G' : 'Ctrl-G') + '</td>' + td2 + tinymce.translate('Find next') + '</td>' + td1 + (isMac ? '&#8984;-Alt-F' : 'Shift-Ctrl-F') + '</td>' + td2 + tinymce.translate('Find previous') + '</td></tr>' + '<tr>' + td1 + (isMac ? '&#8984;-Alt-F' : 'Shift-Ctrl-F') + '</td>' + td2 + tinymce.translate('Replace') + '</td>' + td1 + (isMac ? 'Shift-&#8984;-Alt-F' : 'Shift-Ctrl-R') +'</td>' + td2 + tinymce.translate('Replace all') + '</td></tr></table>';
	div.style.position = 'absolute';
	div.style.left = div.style.bottom = '5px';
	head.appendChild(div);

	// Set CodeMirror cursor to same position as cursor was in TinyMCE:
	var html = editor.getContent({source_view: true});
	html = html.replace(/<span\s+class="CmCaReT"([^>]*)>([^<]*)<\/span>/gm, String.fromCharCode(chr));
	editor.dom.remove(editor.dom.select('.CmCaReT'));

	CodeMirror.defineInitHook(function(inst) 
	{
		// Move cursor to correct position:
		inst.focus();
		var cursor = inst.getSearchCursor(String.fromCharCode(chr), false);
		if (cursor.findNext()) {
			inst.setCursor(cursor.to());
			cursor.replace('');
		}
		
		// Indent all code, if so requested:
		if (editor.settings.codemirror.indentOnInit) {
			var last = inst.lineCount();
			inst.operation(function() {<commit_msg>Fix key shortcut in CodeMirror widget<commit_after><!DOCTYPE html>
<html>
<head>
<script>

/**
 * source.html
 *
 * Copyright 2013-2014 Web Power, www.webpower.nl
 * @author <NAME>
 */

// Global vars:
var tinymce,     // Reference to TinyMCE
	editor,      // Reference to TinyMCE editor
	codemirror,  // CodeMirror instance
	chr = 0,     // Unused utf-8 character, placeholder for cursor
	isMac = /macintosh|mac os/i.test(navigator.userAgent),
	CMsettings;  // CodeMirror settings

function inArray(key, arr)
{
	"use strict";
	arr = '|' + arr.join('|') + '|';
	return arr.indexOf('|'+key+'|') != -1;
}

(function()
{// Initialise (before load)
	"use strict";

	tinymce = parent.tinymce;
	editor = tinymce.activeEditor;
	var i, userSettings = editor.settings.codemirror ? editor.settings.codemirror : null;
	CMsettings = {
		path: userSettings.path || 'CodeMirror',
		indentOnInit: userSettings.indentOnInit || false,
		config: {// Default config
			mode: 'htmlmixed',
			lineNumbers: true,
			lineWrapping: true,
			indentUnit: 1,
			tabSize: 1,
			matchBrackets: true,
			styleActiveLine: true
		},
		jsFiles: [// Default JS files
			'lib/codemirror.js',
			'addon/edit/matchbrackets.js',
			'mode/xml/xml.js',
			'mode/javascript/javascript.js',
			'mode/css/css.js',
			'mode/htmlmixed/htmlmixed.js',
			'addon/dialog/dialog.js',
			'addon/search/searchcursor.js',
			'addon/search/search.js',
			'addon/selection/active-line.js'
		],
		cssFiles: [// Default CSS files
			'lib/codemirror.css',
			'addon/dialog/dialog.css'
		]
	};

	// Merge config
	for (i in userSettings.config) {
		CMsettings.config[i] = userSettings.config[i];
	}
	
	// Merge jsFiles
	for (i in userSettings.jsFiles) {
		if (!inArray(userSettings.jsFiles[i], CMsettings.jsFiles)) {
			CMsettings.jsFiles.push(userSettings.jsFiles[i]);
		}
	}

	// Merge cssFiles
	for (i in userSettings.cssFiles) {
		if (!inArray(userSettings.cssFiles[i], CMsettings.cssFiles)) {
			CMsettings.cssFiles.push(userSettings.cssFiles[i]);
		}
	}

	// Add trailing slash to path
	if (!/\/$/.test(CMsettings.path)) {
		CMsettings.path += '/';
	}

	// Write stylesheets
	for (i = 0; i < CMsettings.cssFiles.length; i++) {
		document.write('<li'+'nk rel="stylesheet" type="text/css" href="' + CMsettings.path + CMsettings.cssFiles[i] + '" />');
	}

	// Write JS source files
	for (i = 0; i < CMsettings.jsFiles.length; i++) {
		document.write('<scr'+'ipt type="text/javascript" src="' + CMsettings.path + CMsettings.jsFiles[i] + '"></scr'+'ipt>');
	}

	window.onload = start;
}());

function start()
{// Initialise (on load)
	"use strict";

	if (typeof(window.CodeMirror) !== 'function') {
		alert('CodeMirror not found in "' + CMsettings.path + '", aborting...');
		return;
	}

	// Create legend for keyboard shortcuts for find & replace:
	var head = parent.document.querySelectorAll('.mce-foot')[0],
		div = parent.document.createElement('div'),
		td1 = '<td style="font-size:11px;background:#777;color:#fff;padding:0 4px">',
		td2 = '<td style="font-size:11px;padding-right:5px">';
	div.innerHTML = '<table cellspacing="0" cellpadding="0" style="border-spacing:4px"><tr>'
		+ td1 + (isMac ? '&#8984;-F' : 'Ctrl-F</td>') + td2 + tinymce.translate('Start search') + '</td>'
		+ td1 + (isMac ? '&#8984;-G' : 'Ctrl-G') + '</td>' + td2 + tinymce.translate('Find next') + '</td>'
		+ td1 + (isMac ? 'Shift-&#8984;-G' : 'Shift-Ctrl-G') + '</td>' + td2 + tinymce.translate('Find previous') + '</td></tr>' + '<tr>'
		+ td1 + (isMac ? '&#8984;-Alt-F' : 'Shift-Ctrl-F') + '</td>' + td2 + tinymce.translate('Replace') + '</td>'
		+ td1 + (isMac ? 'Shift-&#8984;-Alt-F' : 'Shift-Ctrl-R') +'</td>' + td2 + tinymce.translate('Replace all') + '</td></tr></table>';
	div.style.position = 'absolute';
	div.style.left = div.style.bottom = '5px';
	head.appendChild(div);

	// Set CodeMirror cursor to same position as cursor was in TinyMCE:
	var html = editor.getContent({source_view: true});
	html = html.replace(/<span\s+class="CmCaReT"([^>]*)>([^<]*)<\/span>/gm, String.fromCharCode(chr));
	editor.dom.remove(editor.dom.select('.CmCaReT'));

	CodeMirror.defineInitHook(function(inst) 
	{
		// Move cursor to correct position:
		inst.focus();
		var cursor = inst.getSearchCursor(String.fromCharCode(chr), false);
		if (cursor.findNext()) {
			inst.setCursor(cursor.to());
			cursor.replace('');
		}
		
		// Indent all code, if so requested:
		if (editor.settings.codemirror.indentOnInit) {
			var last = inst.lineCount();
			inst.operation(function() {
{'fraction_non_alphanumeric': 0.19601700604162006, 'fraction_numerical': 0.013873349742671738, 'mean_word_length': 3.890043763676149, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837355', 'n_tokens_mistral': 3558, 'n_tokens_neox': 3240, 'n_words': 641}