diff --git a/Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js b/Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js index 91d3f599cda20f105b1c6dd4993c1e7a534c7691..d3e35ae03c7a2806cff9c9b8cca5ccd372e51806 100644 --- a/Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js +++ b/Frontend Angular 4/src/app/layout/matefun/codemirror/matefun-mode-EN.js @@ -28,6 +28,7 @@ const hintWords = require('./hint_words'); var WORD = /[\w$]+/; + var RANGE = 500; var SET = /set\s+([\w\_\d]+)\s*\=/; var DOM = /\:\:/; @@ -37,7 +38,59 @@ var WRITING_SET = /set\s/; var WRITING_COMMENT = /\{\-/; - var RANGE = 500; + // functions definitions + + CodeMirror.defineExtension("functionDefinition", function(editor, options) { + var word = options && options.word || WORD; + var range = options && options.range || RANGE; + var cur = editor.getCursor(), curLine = editor.getLine(cur.line); + var end = cur.ch, start = end; + while (start && word.test(curLine.charAt(start - 1))) --start; + while (end && word.test(curLine.charAt(end + 1))) ++end; + var curWord = start != end && curLine.slice(start, end + 1); + + if (curWord.length > 0){ + var list = [], seen = {}; + var re_digits = new RegExp(/^\d+$/, "g"); + + 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 (!re_digits.exec(m[1]) && (!curWord || m[1] == curWord) && !Object.prototype.hasOwnProperty.call(seen, m[1])) { + seen[m[1]] = true; + list.push(m[1]); + } + } + } + } + + console.log(list); + } + /*options = parseOptions(this, this.getCursor("start"), options); + var selections = this.listSelections() + if (selections.length > 1) return; + // By default, don't allow completion when something is selected. + // A hint function can have a `supportsSelection` property to + // indicate that it can handle selections. + if (this.somethingSelected()) { + if (!options.hint.supportsSelection) return; + // Don't try with cross-line selections + for (var i = 0; i < selections.length; i++) + if (selections[i].head.line != selections[i].anchor.line) return; + } + + if (this.state.completionActive) this.state.completionActive.close(); + var completion = this.state.completionActive = new Completion(this, options); + if (!completion.options.hint) return; + + CodeMirror.signal(this, "startCompletion", this); + completion.update(true);*/ + }); + + // hints CodeMirror.registerHelper("hint", "anyword", function(editor, options) { var word = options && options.word || WORD; diff --git a/Frontend Angular 4/src/app/layout/matefun/matefun.component.html b/Frontend Angular 4/src/app/layout/matefun/matefun.component.html index be31779d5a40203b252915f26ed41f741ad59b92..cee297a779a3987135a53757aa983735bb346108 100755 --- a/Frontend Angular 4/src/app/layout/matefun/matefun.component.html +++ b/Frontend Angular 4/src/app/layout/matefun/matefun.component.html @@ -135,7 +135,7 @@ </ng-template> </form> </div> - <codemirror class="codemirrorPrograma" [(ngModel)]="archivo.contenido" (keyup)="archivoModificado($event)" [config]="configCodeMirror" [ngStyle]="{'font-size': configCodeMirror.fontSize+'px'}"> + <codemirror class="codemirrorPrograma" [(ngModel)]="archivo.contenido" (keyup)="archivoModificado($event)" (click)="clickEnEditor($event)" [config]="configCodeMirror" [ngStyle]="{'font-size': configCodeMirror.fontSize+'px'}"> </codemirror> </div> diff --git a/Frontend Angular 4/src/app/layout/matefun/matefun.component.ts b/Frontend Angular 4/src/app/layout/matefun/matefun.component.ts index 3a0a6ac503cb4914134a9686858fabf424f4c4e7..7402447ea383f3367fe1dbbe67f7e976d7129874 100755 --- a/Frontend Angular 4/src/app/layout/matefun/matefun.component.ts +++ b/Frontend Angular 4/src/app/layout/matefun/matefun.component.ts @@ -456,6 +456,10 @@ export class MateFunComponent { this.codemirror.instance.toggleComment(); } + clickEnEditor(event){ + this.codemirror.instance.functionDefinition(this.codemirror.instance.doc, event); + } + guardarArchivo(){ var regex = /^[A-Z]/ if(this.archivo.nombre.trim() == ""){