<commit_before>var core = require('./core.js')
	, editorNextId = 0
	, fileNameExp = /^(?:.*?[\/\\])?([^\/\\]+)$/
	, listCaptureExp = /^(\s*)((?:[-*+]|\d+\.) )(.*)$/
;


function setFilePath(filePath){
	this.filePath = filePath || '';
	this.fileName = filePath ? this.filePath.replace(fileNameExp, '$1') : 'New File';
}

function Editor(filePath, content){
	var self = this;
	self.editorId = editorNextId++;
	self.el = $('<div id="content-' + self.editorId + '"></div>');
	setFilePath.call(this, filePath);
	self.content = content;
	self.active = false;
	self.editor = CodeMirror(self.el[0], {
		value: content || 'Enter your content here\n```\nfunction test(a, b, c){\n\treturn a + b * c / 100;\n]\n```'
		, mode: "markdown"
		, indentWithTabs: true
		, lineNumbers: true
		, lineWrapping: !!global.settings.wrapmode
		, theme:'ambiance'
		, extraKeys:{
			'Tab':function(cm){ CodeMirror.commands["indentMore"](cm); }
			, 'Shift-Tab':function(cm){ CodeMirror.commands["indentLess"](cm); }
			, 'Enter':function(cm){
				if( cm.somethingSelected() ){
					cm.replaceSelection('\n');
				} else {
					var cursor = cm.getCursor()
						, line = cm.getLine(cursor.line)
						, listMatch = line.match(listCaptureExp)
					;
					if(! listMatch ){
						CodeMirror.commands.newlineAndIndent(cm);
					} else {
						if( ! listMatch[3] ){ // empty line remove the list marker
							cm.setLine(cursor.line, '');
							cm.replaceSelection("\n", "end", "+input");
						} else { // add list marker at start of line
							CodeMirror.commands.newlineAndIndent(cm);
							cm.replaceSelection(listMatch[2], "end");
						}
					}
				}
			}
		}
	});
	self.editor.on('change',function(editor){
		core.emit('editor.change', self, editor.getValue());
	});
	core.emit('editor.ready', self);<commit_msg>new line on selection doesn't keep a selection anymore<commit_after>var core = require('./core.js')
	, editorNextId = 0
	, fileNameExp = /^(?:.*?[\/\\])?([^\/\\]+)$/
	, listCaptureExp = /^(\s*)((?:[-*+]|\d+\.) )(.*)$/
;


function setFilePath(filePath){
	this.filePath = filePath || '';
	this.fileName = filePath ? this.filePath.replace(fileNameExp, '$1') : 'New File';
}

function Editor(filePath, content){
	var self = this;
	self.editorId = editorNextId++;
	self.el = $('<div id="content-' + self.editorId + '"></div>');
	setFilePath.call(this, filePath);
	self.content = content;
	self.active = false;
	self.editor = CodeMirror(self.el[0], {
		value: content || 'Enter your content here\n```\nfunction test(a, b, c){\n\treturn a + b * c / 100;\n]\n```'
		, mode: "markdown"
		, indentWithTabs: true
		, lineNumbers: true
		, lineWrapping: !!global.settings.wrapmode
		, theme:'ambiance'
		, extraKeys:{
			'Tab':function(cm){ CodeMirror.commands["indentMore"](cm); }
			, 'Shift-Tab':function(cm){ CodeMirror.commands["indentLess"](cm); }
			, 'Enter':function(cm){
				if( cm.somethingSelected() ){
					cm.replaceSelection('\n');
					cm.setCursor(cm.getCursor("end"));
				} else {
					var cursor = cm.getCursor()
						, line = cm.getLine(cursor.line)
						, listMatch = line.match(listCaptureExp)
					;
					if(! listMatch ){
						CodeMirror.commands.newlineAndIndent(cm);
					} else {
						if( ! listMatch[3] ){ // empty line remove the list marker
							cm.setLine(cursor.line, '');
							cm.replaceSelection("\n", "end", "+input");
						} else { // add list marker at start of line
							CodeMirror.commands.newlineAndIndent(cm);
							cm.replaceSelection(listMatch[2], "end");
						}
					}
				}
			}
		}
	});
	self.editor.on('change',function(editor){
		core.emit('editor.change', self, editor.getValue());
	});
	core.emit('editor.ready', self);
{'fraction_non_alphanumeric': 0.2042042042042042, 'fraction_numerical': 0.004368004368004368, 'mean_word_length': 3.41978287092883, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7007359', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1261, 'n_words': 230}