Skip to content
Snippets Groups Projects
Commit e82edf21 authored by Franco Pariani's avatar Franco Pariani
Browse files

Fixes and no hint when typing variables of functions

parent d6cc7f62
No related branches found
No related tags found
No related merge requests found
......@@ -29,11 +29,11 @@
var WORD = /[\w$]+/;
var SET = /set\s*([\w\_\d]*?)\s*\=/;
var SET = /set\s+([\w\_\d]+)\s*\=/;
var DOM = /\:\:/;
var FUNS = /([\w\_\d]*)\s*\:\:/;
var FUNS = /([\w\_\d]+)\s+\:\:/;
var FUN = /([\w\_\d]+)\s*\(([\,\w\_\s\d]*)\)\s*\=/;
var ENUMS = /set\s*[\w\_\d]*\s*\=\s*\{(.*?)\}/;
var ENUMS = /set\s+[\w\_\d]+\s*\=\s*\{(.*?)\}/;
var WRITING_SET = /set\s/;
var WRITING_COMMENT = /\{\-/;
......@@ -49,17 +49,19 @@
var list = options && options.list || [], seen = {};
var re_digits = new RegExp(/^\d+$/, "g");
// 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))){
if (previous_line && (match = re_funs.exec(previous_line)) && curLine == ""){
var previous_block = "";
for (var i = 0; i < cur.line; i++){
previous_block += editor.getLine(i) + '\n';
}
var next_block = "";
for (var i = cur.line + 1; i < editor.lastLine(); i++){
for (var i = cur.line + 1; i <= editor.lastLine(); i++){
next_block += editor.getLine(i) + '\n';
}
var file = previous_block + match[1] + ' ()';
......@@ -87,7 +89,7 @@
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])) {
if (!re_digits.exec(m[1]) && (!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
......@@ -110,12 +112,22 @@
previous_block += editor.getLine(i) + '\n';
}
previous_block += previous_part;
// no hint in variables
var hint = true;
var re_funs = new RegExp(FUNS.source, "g"), match_dom, last_match_dom;
while (match_dom = re_funs.exec(previous_block)){ last_match_dom = match_dom };
if (last_match_dom){
var re_current_fun = new RegExp(last_match_dom[1] + '\\s*\\($', "g");
hint = !re_current_fun.exec(previous_part);
}
if (hint){
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])) {
if (!re_digits.exec(vars[i]) && (!curWord || vars[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, vars[i])) {
seen[vars[i]] = true;
list.push(vars[i]);
}
......@@ -130,7 +142,7 @@
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])) {
if (!re_digits.exec(enums[i]) && (!curWord || enums[i].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, enums[i])) {
seen[enums[i]] = true;
list.push(enums[i]);
}
......@@ -145,7 +157,7 @@
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])) {
if (!re_digits.exec(m[1]) && (!curWord || m[1].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
list.push(m[1]);
}
......@@ -164,6 +176,7 @@
}
}
}
}
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
});
......
......@@ -93,7 +93,8 @@ export class MateFunComponent {
theme: 'dracula',
fontSize: 12,
hintOptions: {
completeSingle: false
completeSingle: false,
closeCharacters: /[^\d\w\_]/
}
};
themes = ['3024-day', '3024-night', 'abcdef', 'ambiance-mobile', 'ambiance', 'base16-dark', 'base16-light', 'bespin', 'blackboard', 'cobalt', 'colorforth', 'dracula', 'duotone-dark', 'duotone-light', 'eclipse', 'elegant', 'erlang-dark', 'hopscotch', 'icecoder', 'isotope', 'lesser-dark', 'liquibyte', 'material', 'mbo', 'mdn-like', 'midnight', 'monokai', 'neat', 'neo', 'night', 'panda-syntax', 'paraiso-dark', 'paraiso-light', 'pastel-on-dark', 'railscasts', 'rubyblue', 'seti', 'solarized', 'the-matrix', 'tomorrow-night-bright', 'tomorrow-night-eighties', 'ttcn', 'twilight', 'vibrant-ink', 'xq-dark', 'xq-light', 'yeti', 'zenburn']
......@@ -417,7 +418,7 @@ export class MateFunComponent {
}
archivoModificado(event){
if (!event.ctrlKey && !event.shiftKey && !event.altKey){
if (!event.ctrlKey && !event.altKey){
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){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment