Commit d6cc7f62 authored by Franco Pariani's avatar Franco Pariani
Browse files

Adding function name when press Enter before definition

parent 7f01d245
......@@ -49,81 +49,44 @@
var list = options && options.list || [], seen = {};
var previous_part = curLine.slice(0, start);
var re_w_s = new RegExp(WRITING_SET.source, "g");
var re_w_c = new RegExp(WRITING_COMMENT.source, "g");
if (!re_w_s.exec(previous_part) && !re_w_c.exec(previous_part)){
// sets
var re_dom = new RegExp(DOM.source, "g");
if (re_dom.exec(previous_part)){
var re_sets = new RegExp(SET.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re_sets.exec(text)) {
if (line == cur.line && m[1] === curWord) continue;
if ((!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
}
}
}
// add default sets
var default_sets = hintWords.EN_default_sets();
for (var i = 0; i < default_sets.length; i++) {
if ((!curWord || default_sets[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, default_sets[i])) {
seen[default_sets[i]] = true;
list.push(default_sets[i]);
}
}
}else{
// get variables of function
// not word = 'Enter'
if (options.key == 'Enter'){
var previous_line = editor.getLine(cur.line - 1);
var re_funs = new RegExp(FUNS.source, "g"), match;
if (previous_line && (match = re_funs.exec(previous_line))){
var previous_block = "";
for (var i = 1; i < cur.line; i++){
for (var i = 0; i < cur.line; i++){
previous_block += editor.getLine(i) + '\n';
}
previous_block += previous_part;
var re_fun = new RegExp(FUN.source, "g"), match, last_match;
while (match = re_fun.exec(previous_block)){ last_match = match };
if (last_match){
var vars = last_match[2].replace(/\s/g,'').split(',');
for (var i = 0; i < vars.length; i++) {
if ((!curWord || vars[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, vars[i])) {
seen[vars[i]] = true;
list.push(vars[i]);
}
}
var next_block = "";
for (var i = cur.line + 1; i < editor.lastLine(); i++){
next_block += editor.getLine(i) + '\n';
}
var file = previous_block + match[1] + ' ()';
if (next_block != ""){
file = file + '\n' + next_block;
}
editor.setValue(file);
editor.setCursor(CodeMirror.Pos(cur.line, match[1].length + 2));
}
}else{
var previous_part = curLine.slice(0, start);
var re_w_s = new RegExp(WRITING_SET.source, "g");
var re_w_c = new RegExp(WRITING_COMMENT.source, "g");
if (!re_w_s.exec(previous_part) && !re_w_c.exec(previous_part)){
// sets
var re_dom = new RegExp(DOM.source, "g");
if (re_dom.exec(previous_part)){
var re_sets = new RegExp(SET.source, "g");
// get enums
var re_enums = new RegExp(ENUMS.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re_enums.exec(text)) {
var enums = m[1].replace(/\s/g,'').split(',');
for (var i = 0; i < enums.length; i++) {
if ((!curWord || enums[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, enums[i])) {
seen[enums[i]] = true;
list.push(enums[i]);
}
}
}
}
}
// get functions
var re_funs = new RegExp(FUNS.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re_funs.exec(text)) {
while (m = re_sets.exec(text)) {
if (line == cur.line && m[1] === curWord) continue;
if ((!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
......@@ -131,12 +94,71 @@
}
}
}
// add default functions
var default_functions = hintWords.EN_functions();
for (var i = 0; i < default_functions.length; i++) {
if ((!curWord || default_functions[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, default_functions[i])) {
seen[default_functions[i]] = true;
list.push(default_functions[i]);
// add default sets
var default_sets = hintWords.EN_default_sets();
for (var i = 0; i < default_sets.length; i++) {
if ((!curWord || default_sets[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, default_sets[i])) {
seen[default_sets[i]] = true;
list.push(default_sets[i]);
}
}
}else{
// get variables of function
var previous_block = "";
for (var i = 0; i < cur.line; i++){
previous_block += editor.getLine(i) + '\n';
}
previous_block += previous_part;
var re_fun = new RegExp(FUN.source, "g"), match, last_match;
while (match = re_fun.exec(previous_block)){ last_match = match };
if (last_match){
var vars = last_match[2].replace(/\s/g,'').split(',');
for (var i = 0; i < vars.length; i++) {
if ((!curWord || vars[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, vars[i])) {
seen[vars[i]] = true;
list.push(vars[i]);
}
}
// get enums
var re_enums = new RegExp(ENUMS.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re_enums.exec(text)) {
var enums = m[1].replace(/\s/g,'').split(',');
for (var i = 0; i < enums.length; i++) {
if ((!curWord || enums[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, enums[i])) {
seen[enums[i]] = true;
list.push(enums[i]);
}
}
}
}
}
// get functions
var re_funs = new RegExp(FUNS.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re_funs.exec(text)) {
if ((!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
}
}
}
// add default functions
var default_functions = hintWords.EN_functions();
for (var i = 0; i < default_functions.length; i++) {
if ((!curWord || default_functions[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, default_functions[i])) {
seen[default_functions[i]] = true;
list.push(default_functions[i]);
}
}
}
}
......
......@@ -418,7 +418,7 @@ export class MateFunComponent {
archivoModificado(event){
if (!event.ctrlKey && !event.shiftKey && !event.altKey){
if (/^[\w\_\d]$/.test(event.key))
if (/^[\w\_\d]$/.test(event.key) || event.key == 'Enter')
this.codemirror.instance.showHint(event);
if(this.copiaNombreArchivo!=this.archivo.nombre || this.copiaContenidoArchivo != this.archivo.contenido){
this.modificado = true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment