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

Jump to definition feature

parent 1b64d067
No related branches found
No related tags found
No related merge requests found
......@@ -484,4 +484,42 @@ var mac = /Mac/.test(navigator.platform);
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
}
};
CodeMirror.defineExtension("jumpToDefinition", 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 found = false;
var re_funs = new RegExp(COMPLETE_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 && !found; 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;
found = true;
var newCursor = editor.getCursor();
newCursor.line = line;
newCursor.ch = text.indexOf(m[1]);
editor.setCursor(newCursor);
editor.cm.closeFunctionDefinition();
}
}
}
}
}
});
});
......@@ -135,6 +135,7 @@
<label><b>Ctrl+G</b> {{ "i18n.shortcuts.saveFile" | translate }}</label>
<label><b>Ctrl+{{ "i18n.shortcuts.space" | translate }}</b> {{ "i18n.shortcuts.autocomplete" | translate }}</label>
<label><b>Ctrl+Shift+K</b> {{ "i18n.shortcuts.comment" | translate }}</label>
<label><b>Alt+.</b> {{ "i18n.shortcuts.functionNavigation" | translate }}</label>
</div>
</div>
</ng-template>
......
......@@ -453,9 +453,8 @@ export class MateFunComponent {
}else{
this.modificado = false;
}
}
if (event.ctrlKey && event.shiftKey && event.key == 'K')
this.codemirror.instance.toggleComment();
}else if (event.ctrlKey && event.shiftKey && event.key == 'K') this.codemirror.instance.toggleComment();
else if (event.altKey && event.key == '.') this.codemirror.instance.jumpToDefinition(this.codemirror.instance.doc, event);
}
clickEnEditor(event){
......
......@@ -129,7 +129,8 @@
"saveFile" : "Save File",
"autocomplete" : "Autocomplete",
"space" : "Space",
"comment" : "Comment/Uncomment"
"comment" : "Comment/Uncomment",
"functionNavigation" : "Jump to the definition"
}
}
}
......@@ -129,7 +129,8 @@
"saveFile" : "Guardar archivo",
"autocomplete" : "Autocompletar",
"space" : "Espacio",
"comment" : "Comentar/Descomentar"
"comment" : "Comentar/Descomentar",
"functionNavigation" : "Saltar a la definición"
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment