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

Go to line in file preview with external files

parent f4ecc13a
No related branches found
No related tags found
No related merge requests found
......@@ -48,6 +48,7 @@ export class ArchivosComponent {
preview: string = '';
directorioActual:any;
sortFunction:any;
checked: boolean;
configCodeMirror = JSON.parse(sessionStorage.getItem('codeMirrorConfig')) ;
constructor(
......@@ -71,9 +72,12 @@ export class ArchivosComponent {
@ViewChild(CodemirrorComponent) codemirror: CodemirrorComponent;
ngOnInit(){
this.checked = false;
this.route.queryParams.subscribe(params => {
this.file_loaded = params['file'] || null;
});
this.function_to_find = params['word'] || null;
});
this.sortFunction = 'tipo'
let cedula = this.authService.getUser().cedula;
......@@ -556,4 +560,11 @@ export class ArchivosComponent {
}
});
}
ngAfterViewChecked(){
if(this.codemirror !== undefined && this.codemirror.instance.doc.getValue() !== "" && this.function_to_find !== null && !this.checked){
this.checked = true;
this.codemirror.instance.jumpToDefinitionByWord(this.codemirror.instance.doc, this.function_to_find);
}
}
}
......@@ -99,7 +99,7 @@
if (file_found !== null){
editor.cm.closeFunctionDefinition();
window.matefunComponent.component.goToFilesPreview(file_found);
window.matefunComponent.component.goToFilesPreview(file_found, curWord);
}
}
}
......@@ -119,6 +119,30 @@
var WRITING_SET = /set\s/;
var WRITING_COMMENT = /\{\-/;
CodeMirror.defineExtension("jumpToDefinitionByWord", function(editor, word){
var re_digits = new RegExp(/^\d+$/, "g");
var re_funs = new RegExp(FUNS.source, "g");
var seen = {};
var found = false;
for (var dir = -1; dir <= 1 && !found; dir += 2) {
var line = editor.firstLine(), endLine = Math.min(Math.max(line + dir * RANGE, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine && !found; line += dir) {
var text = editor.getLine(line), m;
while ((m = re_funs.exec(text)) && !found) {
if (!re_digits.exec(m[1]) && (!word || m[1].lastIndexOf(word, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
found = true;
var newCursor = editor.getCursor();
newCursor.line = line;
newCursor.ch = text.indexOf(word);
editor.setCursor(newCursor);
}
}
}
}
});
// hints
CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
......
......@@ -100,7 +100,7 @@
if (file_found !== null){
editor.cm.closeFunctionDefinition();
window.matefunComponent.component.goToFilesPreview(file_found);
window.matefunComponent.component.goToFilesPreview(file_found, curWord);
}
}
});
......@@ -119,6 +119,30 @@
var RANGE = 500;
CodeMirror.defineExtension("jumpToDefinitionByWord", function(editor, word){
var re_digits = new RegExp(/^\d+$/, "g");
var re_funs = new RegExp(FUNS.source, "g");
var seen = {};
var found = false;
for (var dir = -1; dir <= 1 && !found; dir += 2) {
var line = editor.firstLine(), endLine = Math.min(Math.max(line + dir * RANGE, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine && !found; line += dir) {
var text = editor.getLine(line), m;
while ((m = re_funs.exec(text)) && !found) {
if (!re_digits.exec(m[1]) && (!word || m[1].lastIndexOf(word, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[1])) {
seen[m[1]] = true;
found = true;
var newCursor = editor.getCursor();
newCursor.line = line;
newCursor.ch = text.indexOf(word);
editor.setCursor(newCursor);
}
}
}
}
});
CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
var word = options && options.word || WORD;
var range = options && options.range || RANGE;
......@@ -584,7 +608,6 @@
blockCommentEnd: "-}",
lineComment: "--"
};
});
CodeMirror.defineMIME("text/x-matefun", "matefun-ES");
......
......@@ -475,9 +475,9 @@ export class MateFunComponent {
}
}
goToFilesPreview(file_found){
goToFilesPreview(file_found, word){
let navigationExtras: NavigationExtras = {
queryParams: { file: file_found.id },
queryParams: { file: file_found.id, word: word },
skipLocationChange: true
};
this.router.navigate(['/archivos'], navigationExtras);
......
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