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

Finding functions that matches with the clicked word

parent 430ee10f
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
const hintWords = require('./hint_words'); const hintWords = require('./hint_words');
var WORD = /[\w$]+/; var WORD = /[\w$]+/;
var RANGE = 500;
var SET = /set\s+([\w\_\d]+)\s*\=/; var SET = /set\s+([\w\_\d]+)\s*\=/;
var DOM = /\:\:/; var DOM = /\:\:/;
...@@ -37,7 +38,59 @@ ...@@ -37,7 +38,59 @@
var WRITING_SET = /set\s/; var WRITING_SET = /set\s/;
var WRITING_COMMENT = /\{\-/; 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) { CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
var word = options && options.word || WORD; var word = options && options.word || WORD;
......
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
</ng-template> </ng-template>
</form> </form>
</div> </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> </codemirror>
</div> </div>
......
...@@ -456,6 +456,10 @@ export class MateFunComponent { ...@@ -456,6 +456,10 @@ export class MateFunComponent {
this.codemirror.instance.toggleComment(); this.codemirror.instance.toggleComment();
} }
clickEnEditor(event){
this.codemirror.instance.functionDefinition(this.codemirror.instance.doc, event);
}
guardarArchivo(){ guardarArchivo(){
var regex = /^[A-Z]/ var regex = /^[A-Z]/
if(this.archivo.nombre.trim() == ""){ if(this.archivo.nombre.trim() == ""){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment