<commit_before>/**
 *	REditor javascript class
 *
 *	@author <NAME>
 */
REditor = function( textAreaId ){
	
	this.textArea		= $( "#"+textAreaId );
	var textArea 		= document.getElementById( textAreaId );
	this.editor 		= CodeMirror.fromTextArea( textArea, {
		mode 			: "r",
		theme			: "neat",
		lineNumbers		: true,
		styleActiveLine	: true,
		matchBrackets	: true,
//		extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
	    foldGutter: true,
	    gutters: [ "CodeMirror-linenumbers" , "CodeMirror-foldgutter" ],
		extraKeys: { "Ctrl-Space": "autocomplete" , "Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); } }
	});
	
	this.init();
};

REditor.prototype.init = function(){
	var $this	= this;
	
	
	CodeMirror.hint.r = function(cm) {
		var inner = { from: cm.getCursor(), to: cm.getCursor(), list: [] };
		var hints = $this.getHints();
		
		var doc 	= cm.getDoc();
	    var POS 	= doc.getCursor();
	    var mode 	= CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(POS).state).mode.name;
	    var line 	= doc.getLine( POS.line )
		line		= StringUtils.getLastWord( line , [" ", "\n"], POS.ch ).trim();
		
		if( Utils.isBlankString(line) ){
			inner.list = inner.list.concat( hints );
		} else {
			var list = [];
			for( var i in hints ){
				var hint =  hints[ i ];
				if( StringUtils.contains( hint , line ) ){
					list.push( hint );
				}
			}
			inner.list = inner.list.concat( list );
		}
		return inner;
	};
	
};
/**
 * Returns the available hints 
 * @returns {Array}
 */
REditor.prototype.getHints = function(){
	var hints =	 REditor.rFunctions;
	
	return hints;
};

/**
 * Returns the text entered into the editor
 */
REditor.prototype.getValue = function(){
	return this.editor.getValue();
};

/**
 * Set the editor content.
 * @param value
 */
REditor.prototype.setValue = function( value ){
	return this.editor.setValue( value );
};

<commit_msg> fixed r editor autocompletition<commit_after>/**
 *	REditor javascript class
 *
 *	@author <NAME>
 */
REditor = function( textAreaId ){
	
	this.textArea		= $( "#"+textAreaId );
	var textArea 		= document.getElementById( textAreaId );
	this.editor 		= CodeMirror.fromTextArea( textArea, {
		mode 			: "r",
		theme			: "neat",
		lineNumbers		: true,
		styleActiveLine	: true,
		matchBrackets	: true,
//		extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
	    foldGutter: true,
	    gutters: [ "CodeMirror-linenumbers" , "CodeMirror-foldgutter" ],
		extraKeys: { "Ctrl-Space": "autocomplete" , "Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); } }
	});
	
	this.init();
};

REditor.prototype.init = function(){
	var $this	= this;
	
	
	CodeMirror.hint.r = function(cm) {
		var hints 	= $this.getHints();
	    var cur 	= cm.getCursor();
	    
	    var token 	= cm.getTokenAt(cur), start, end, search;
	    if (token.string.match(/^[.\w@]\w*$/)) {
	        search = token.string;
	        start = token.start;
	        end = token.end;
	    } else {
	        start = end = cur.ch;
	        search = "";
	    }
	    
	    var result = [];
		if( StringUtils.isBlank(search) ){
			result = hints ;
		} else {
			var list = [];
			for( var i in hints ){
				var hint =  hints[ i ];
				if( StringUtils.contains( hint , search ) ){
					list.push( hint );
				}
			}
			result = list ;
		}
		return {list: result, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
	};
	
};
/**
 * Returns the available hints 
 * @returns {Array}
 */
REditor.prototype.getHints = function(){
	var hints =	 REditor.rFunctions;
	
	return hints;
};

/**
 * Returns the text entered into the editor
 */
REditor.prototype.getValue = function(){
	return this.editor.getValue();
};

/**
 * Set the editor content.
 * @param value
 */
REditor.prototype.setValue = function( value ){
	return this.editor.setValue( value );
};


{'fraction_non_alphanumeric': 0.1681508643268727, 'fraction_numerical': 0.0, 'mean_word_length': 2.9698544698544698, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, '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': '1882294', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1336, 'n_words': 296}