@@ -49,6 +49,8 @@ var ICEcoder = {
49
49
colorDropTgtBGFile : '#f80' , // Drop dir target background color
50
50
prevTab : 0 , // Previous tab to current
51
51
serverQueueItems : [ ] , // Array of URLs to call in order
52
+ origCursorPos : false , // Original cursor position before jump to definition
53
+ origSelectionPos : false , // Original selection position before jump to definition
52
54
previewWindow : false , // Target variable for the preview window
53
55
previewWindowLoading : false , // Loading state of preview window
54
56
pluginIntervalRefs : [ ] , // Array of plugin interval refs
@@ -685,50 +687,7 @@ var ICEcoder = {
685
687
// If CTRL key down
686
688
if ( evt . ctrlKey ) {
687
689
setTimeout ( function ( ic ) {
688
- // Get cM and word under mouse pointer
689
- let cM = thisCM ;
690
- let word = ( cM . getRange ( cM . findWordAt ( cM . getCursor ( ) ) . anchor , cM . findWordAt ( cM . getCursor ( ) ) . head ) ) ;
691
-
692
- // Get result and number of results for word in functions and classes from index JSON object list
693
- let result = null ;
694
- let numResults = 0 ;
695
- let filePath = ic . openFiles [ ic . selectedTab - 1 ] ;
696
- let filePathExt = filePath . substr ( filePath . lastIndexOf ( "." ) + 1 ) ;
697
-
698
- if ( "undefined" !== typeof ic . indexData . functions ) {
699
- for ( i in ic . indexData . functions [ filePathExt ] ) {
700
- if ( i === word ) {
701
- result = ic . indexData . functions [ filePathExt ] [ i ] ;
702
- numResults ++ ;
703
- }
704
- }
705
- }
706
-
707
- if ( "undefined" !== typeof ic . indexData . class ) {
708
- for ( i in ic . indexData . classes [ filePathExt ] ) {
709
- if ( i === word ) {
710
- result = ic . indexData . classes [ filePathExt ] [ i ] ;
711
- numResults ++ ;
712
- }
713
- }
714
- }
715
-
716
- // If we have a single result and the cursor isn't already on the definition of it we can jump to where it's defined
717
- if ( 1 === numResults && - 1 === [ null , "def" ] . indexOf ( cM . getTokenTypeAt ( cM . getCursor ( ) ) ) ) {
718
- ic . openFile ( result . filePath . replace ( docRoot , "" ) ) ;
719
- ic . goFindAfterOpenInt = setInterval ( function ( result ) {
720
- if ( ic . openFiles [ ic . selectedTab - 1 ] == result . filePath . replace ( docRoot , "" ) && ! ic . loadingFile ) {
721
- cM = ic . getcMInstance ( ) ;
722
- setTimeout ( function ( result ) {
723
- ic . goToLine ( result . range . from . line + 1 ) ;
724
- cM . setSelection ( { line : result . range . from . line , ch : result . range . from . ch } , { line : result . range . to . line , ch : result . range . to . ch } ) ;
725
- } , 20 , result ) ;
726
- clearInterval ( ic . goFindAfterOpenInt ) ;
727
- }
728
- } , 20 , result ) ;
729
- }
730
-
731
- ic . mouseDownInCM = "editor" ;
690
+ ic . jumpToDefinition ( ) ;
732
691
} , 0 , this ) ;
733
692
}
734
693
} ,
@@ -1352,34 +1311,85 @@ var ICEcoder = {
1352
1311
}
1353
1312
} ,
1354
1313
1355
- // Jump to and highlight the function definition current token
1314
+ // Jump to and highlight the function definition current token or back again to where we were
1356
1315
jumpToDefinition : function ( ) {
1357
- let thisCM , tokenString , defVars ;
1316
+ let thisCM , word , cursorBack1Char , result , numResults , filePath , filePathExt ;
1358
1317
1359
1318
thisCM = this . getThisCM ( ) ;
1360
1319
1361
- tokenString = thisCM . getTokenAt ( thisCM . getCursor ( ) ) . string ;
1362
-
1363
- if ( thisCM . somethingSelected ( ) && this . origCurorPos ) {
1364
- thisCM . setCursor ( this . origCurorPos ) ;
1320
+ // We have an original cursor or selection position, so we'll jump back to it
1321
+ if ( false !== this . origCursorPos || false !== this . origSelectionPos ) {
1322
+ // Jump to the original position (selection/cursor) we have and set selection/cursor
1323
+ if ( false !== this . origSelectionPos ) {
1324
+ this . goToLine ( this . origSelectionPos . anchor . line + 1 ) ;
1325
+ thisCM . setSelection ( this . origSelectionPos . anchor , this . origSelectionPos . head ) ;
1326
+ } else {
1327
+ this . goToLine ( this . origCursorPos . line + 1 ) ;
1328
+ thisCM . setCursor ( this . origCursorPos ) ;
1329
+ }
1330
+ // Reset flags for next time
1331
+ this . origSelectionPos = false ;
1332
+ this . origCursorPos = false ;
1365
1333
} else {
1366
- this . origCurorPos = thisCM . getCursor ( ) ;
1367
- defVars = [
1368
- "var " + tokenString ,
1369
- "function " + tokenString ,
1370
- tokenString + "=function" , tokenString + "= function" , tokenString + " =function" , tokenString + " = function" ,
1371
- tokenString + "=new function" , tokenString + "= new function" , tokenString + " =new function" , tokenString + " = new function" ,
1372
- "window['" + tokenString + "']" , "window[\"" + tokenString + "\"]" ,
1373
- "this['" + tokenString + "']" , "this[\"" + tokenString + "\"]" ,
1374
- tokenString + ":" , tokenString + " :" ,
1375
- "def " + tokenString ,
1376
- "class " + tokenString
1377
- ] ;
1378
- for ( let i = 0 ; i < defVars . length ; i ++ ) {
1379
- if ( this . findReplace ( defVars [ i ] , false , false , false ) ) {
1380
- break ;
1334
+ // Set flags for original section or cursor so we can return next time
1335
+ if ( thisCM . listSelections ( ) [ 0 ] ) {
1336
+ this . origSelectionPos = thisCM . listSelections ( ) [ 0 ] ;
1337
+ } else {
1338
+ this . origCursorPos = thisCM . getCursor ( ) ;
1339
+ }
1340
+
1341
+ // Get word
1342
+ word = thisCM . getRange ( thisCM . findWordAt ( thisCM . getCursor ( ) ) . anchor , thisCM . findWordAt ( thisCM . getCursor ( ) ) . head ) ;
1343
+ // If we got parens, try back 1 character to get word
1344
+ if ( - 1 < word . indexOf ( "(" ) ) {
1345
+ cursorBack1Char = { line : thisCM . getCursor ( ) . line , ch : thisCM . getCursor ( ) . ch - 1 } ;
1346
+ word = thisCM . getRange ( thisCM . findWordAt ( cursorBack1Char ) . anchor , thisCM . findWordAt ( cursorBack1Char ) . head ) ;
1347
+ }
1348
+
1349
+ // Set start point for result and number of results for word in functions and classes from index JSON object list
1350
+ result = null ;
1351
+ numResults = 0 ;
1352
+ // Identify the file path and extension
1353
+ filePath = this . openFiles [ this . selectedTab - 1 ] ;
1354
+ filePathExt = filePath . substr ( filePath . lastIndexOf ( "." ) + 1 ) ;
1355
+
1356
+ // Find the word within extention type in functions list data
1357
+ if ( "undefined" !== typeof this . indexData . functions ) {
1358
+ for ( i in this . indexData . functions [ filePathExt ] ) {
1359
+ if ( i === word ) {
1360
+ result = this . indexData . functions [ filePathExt ] [ i ] ;
1361
+ numResults ++ ;
1362
+ }
1381
1363
}
1382
1364
}
1365
+
1366
+ // Find the word within extention type in classes list data
1367
+ if ( "undefined" !== typeof this . indexData . class ) {
1368
+ for ( i in this . indexData . classes [ filePathExt ] ) {
1369
+ if ( i === word ) {
1370
+ result = this . indexData . classes [ filePathExt ] [ i ] ;
1371
+ numResults ++ ;
1372
+ }
1373
+ }
1374
+ }
1375
+
1376
+ // If we have a single result and the cursor isn't already on the definition of it, we can jump to where it's defined
1377
+ if ( 1 === numResults && - 1 === [ null , "def" ] . indexOf ( thisCM . getTokenTypeAt ( thisCM . getCursor ( ) ) ) ) {
1378
+ // Open file (or switch tab to it if already open) and find when editor showing
1379
+ this . openFile ( result . filePath . replace ( docRoot , "" ) ) ;
1380
+ this . goFindAfterOpenInt = setInterval ( function ( result ) {
1381
+ if ( ICEcoder . openFiles [ ICEcoder . selectedTab - 1 ] == result . filePath . replace ( docRoot , "" ) && ! ICEcoder . loadingFile ) {
1382
+ thisCM = ICEcoder . getcMInstance ( ) ;
1383
+ setTimeout ( function ( result ) {
1384
+ ICEcoder . goToLine ( result . range . from . line + 1 ) ;
1385
+ thisCM . setSelection ( { line : result . range . from . line , ch : result . range . from . ch } , { line : result . range . to . line , ch : result . range . to . ch } ) ;
1386
+ } , 20 , result ) ;
1387
+ clearInterval ( ICEcoder . goFindAfterOpenInt ) ;
1388
+ }
1389
+ } , 20 , result ) ;
1390
+ }
1391
+
1392
+ this . mouseDownInCM = "editor" ;
1383
1393
}
1384
1394
} ,
1385
1395
@@ -4826,7 +4836,7 @@ var ICEcoder = {
4826
4836
return false ;
4827
4837
4828
4838
// CTRL/Cmd + numeric minus (Close tab)
4829
- } else if ( ( key == 109 || key == 189 ) && true === ctrlOrCmd ) {
4839
+ } else if ( ( 109 === key || 189 === key ) && true === ctrlOrCmd ) {
4830
4840
"content" === area
4831
4841
? this . removeLines ( )
4832
4842
: this . closeTab ( this . selectedTab ) ;
0 commit comments