Jump to Definition, opening up findReplace func

New function jumptToDefinition. This takes token at the current cursor
position and then looks for that function definition as a set piece of
text 'function '+tokenString. This is triggered from CTRL+J so you can
hit this whenever you're on a function call and it will jump to it's
declaration.
In doing this I have repurposed the 1st param in findReplace function to
now accept a string to find. Previously we had this set to action, but
this variable was never used, must have just been a placeholder. In the
couple of places we call this function now we are passing the find input
box value.
This commit is contained in:
Matt Pass
2013-05-04 15:19:31 +01:00
parent bcc86e160f
commit d7a8b35ded

View File

@@ -410,6 +410,15 @@ var ICEcoder = {
cM.setCursor(line-1,ch);
},
// Jump to and highlight the function definition current token
jumpToDefinition: function() {
var cM, tokenString;
cM = ICEcoder.getcMInstance();
tokenString = cM.getTokenAt(cM.getCursor()).string;
top.ICEcoder.findReplace("function "+tokenString,false,true);
},
// ==============
// FILES
// ==============
@@ -867,11 +876,11 @@ var ICEcoder = {
},
// Find & replace text according to user selections
findReplace: function(action,resultsOnly,buttonClick) {
findReplace: function(findString,resultsOnly,buttonClick) {
var find, replace, results, cM, content, lineCount, numChars, charsToCursor, charCount, cursor, replaceQS, targetQS;
// Determine our find & replace strings and the length of them
find = top.document.getElementById('find').value.toLowerCase();
find = findString.toLowerCase();
replace = top.document.getElementById('replace').value;
results = top.document.getElementById('results');
@@ -879,7 +888,6 @@ var ICEcoder = {
cM = ICEcoder.getcMInstance();
if (cM && find.length>0 && document.findAndReplace.target.value=="this document") {
content = cM.getValue().toLowerCase();
// Find & replace the next instance, or all?
if (document.findAndReplace.connector.value=="and") {
if (document.findAndReplace.replaceAction.value=="replace" && cM.getSelection().toLowerCase()==find) {
@@ -1547,7 +1555,7 @@ var ICEcoder = {
// Update and show/hide found results display?
updateResultsDisplay: function(showHide) {
ICEcoder.findReplace('find',true,false);
ICEcoder.findReplace(top.document.getElementById('find').value,true,false);
document.getElementById('results').style.display = showHide=="show" ? 'inline-block' : 'none';
},
@@ -1639,7 +1647,7 @@ var ICEcoder = {
// Redo our find display
top.ICEcoder.findMode = false;
ICEcoder.findReplace('find',true,false);
ICEcoder.findReplace(top.document.getElementById('find').value,true,false);
// Rerun JS Hint
if (top.ICEcoder.codeAssist) {top.ICEcoder.updateHints()};
@@ -2123,6 +2131,11 @@ var ICEcoder = {
top.ICEcoder.addSnippet();
return false;
// CTRL+J (Jump to definition)
} else if(key==74 && evt.ctrlKey && area=="content") {
top.ICEcoder.jumpToDefinition();
return false;
// ESC in content area (Comment/Uncomment line)
} else if(key==27 && area == "content") {
top.ICEcoder.lineCommentToggle();