@@ -4925,39 +4925,40 @@ var ICEcoder = {
4925
4925
4926
4926
// Reset the state of keys back to the normal state
4927
4927
resetKeys : function ( evt ) {
4928
- var key , cM ;
4928
+ let key , thisCM ;
4929
4929
4930
4930
key = evt . keyCode ?? evt . which ?? evt . charCode ;
4931
4931
4932
- if ( key == 112 && true === this . codeZoomedOut ) {
4933
- cM = this . getcMInstance ( ) ;
4932
+ if ( 112 === key && true === this . codeZoomedOut ) {
4933
+ thisCM = this . getcMInstance ( ) ;
4934
4934
// For every line in the current editor, remove code-zoomed-out class if not a function/class declaration line
4935
- for ( var i = 0 ; i < cM . lineCount ( ) ; i ++ ) {
4936
- var nonDeclareLine = true ;
4937
- for ( var j = 0 ; j < this . functionClassList . length ; j ++ ) {
4938
- if ( this . functionClassList [ j ] . line == i ) {
4935
+ for ( let i = 0 ; i < thisCM . lineCount ( ) ; i ++ ) {
4936
+ let nonDeclareLine = true ;
4937
+ for ( let j = 0 ; j < this . functionClassList . length ; j ++ ) {
4938
+ if ( i === this . functionClassList [ j ] . line ) {
4939
4939
nonDeclareLine = false ;
4940
4940
}
4941
4941
}
4942
- if ( nonDeclareLine ) {
4943
- cM . removeLineClass ( i , "wrap" , "code-zoomed-out" ) ;
4942
+ if ( true === nonDeclareLine ) {
4943
+ thisCM . removeLineClass ( i , "wrap" , "code-zoomed-out" ) ;
4944
4944
}
4945
4945
}
4946
4946
// Refresh is necessary to re-draw lines
4947
- cM . refresh ( ) ;
4947
+ thisCM . refresh ( ) ;
4948
4948
4949
4949
// Go to line chosen if any
4950
- var cursor = cM . getCursor ( ) ;
4950
+ let cursor = thisCM . getCursor ( ) ;
4951
4951
this . goToLine ( cursor . line + 1 , cursor . ch , false ) ;
4952
4952
4953
4953
this . codeZoomedOut = false ;
4954
4954
}
4955
4955
this . cmdKey = false ;
4956
4956
} ,
4957
4957
4958
+ // Handle Enter and Escape keys in modals
4958
4959
handleModalKeyUp : function ( evt , page ) {
4959
4960
const key = evt . keyCode ?? evt . which ?? evt . charCode ;
4960
- const target = get ( 'blackMask' ) ? get ( 'blackMask' ) : parent . get ( 'blackMask' ) ;
4961
+ const target = get ( 'blackMask' ) ?? parent . get ( 'blackMask' ) ;
4961
4962
4962
4963
if ( "settings" === page && 13 === key ) {
4963
4964
get ( page + 'IFrame' ) . contentWindow . submitSettings ( ) ;
@@ -4969,65 +4970,65 @@ var ICEcoder = {
4969
4970
4970
4971
// Add snippet code completion
4971
4972
addSnippet : function ( ) {
4972
- var thisCM , lineNo , whiteSpace , content ;
4973
+ let thisCM , lineNo , whiteSpace , content ;
4973
4974
4974
4975
// Get line content after trimming whitespace
4975
4976
thisCM = this . getThisCM ( ) ;
4976
4977
lineNo = thisCM . getCursor ( ) . line ;
4977
4978
whiteSpace = thisCM . getLine ( lineNo ) . length - thisCM . getLine ( lineNo ) . replace ( / ^ \s \s * / , '' ) . length ;
4978
4979
content = thisCM . getLine ( lineNo ) . slice ( whiteSpace ) ;
4979
4980
// function snippet
4980
- if ( content . slice ( 0 , 8 ) == "function" ) {
4981
- this . doSnippet ( 'function' , 'function VAR() {\nINDENT\tCURSOR\nINDENT}' ) ;
4982
- // if snippet
4983
- } else if ( content . slice ( 0 , 2 ) == "if" ) {
4984
- this . doSnippet ( 'if' , 'if (CURSOR) {\nINDENT\t\nINDENT}' ) ;
4985
- // for snippet
4986
- } else if ( content . slice ( 0 , 3 ) == "for" ) {
4987
- this . doSnippet ( 'for' , 'for (let i = 0; i <CURSOR; i++) {\nINDENT\t\nINDENT}' ) ;
4981
+ if ( "function" === content . slice ( 0 , 8 ) ) {
4982
+ this . doSnippet ( 'function' , 'function VAR() {\nINDENT\tCURSOR\nINDENT}' ) ;
4983
+ // if snippet
4984
+ } else if ( "if" === content . slice ( 0 , 2 ) ) {
4985
+ this . doSnippet ( 'if' , 'if (CURSOR) {\nINDENT\t\nINDENT}' ) ;
4986
+ // for snippet
4987
+ } else if ( "for" === content . slice ( 0 , 3 ) ) {
4988
+ this . doSnippet ( 'for' , 'for (let i = 0; i <CURSOR; i++) {\nINDENT\t\nINDENT}' ) ;
4988
4989
}
4989
4990
} ,
4990
4991
4991
4992
// Action a snippet
4992
- doSnippet : function ( tgtString , replaceString ) {
4993
- var thisCM , lineNo , lineContents , remainder , strPos , replacedLine , whiteSpace , curPos , sPos , lineNoCount ;
4993
+ doSnippet : function ( tgtString , replaceString ) {
4994
+ let thisCM , lineNo , lineContents , remainder , strPos , replacedLine , whiteSpace , curPos , sPos , lineNoCount ;
4994
4995
4995
4996
// Get line contents
4996
4997
thisCM = this . getThisCM ( ) ;
4997
4998
lineNo = thisCM . getCursor ( ) . line ;
4998
4999
lineContents = thisCM . getLine ( lineNo ) ;
4999
5000
5000
5001
// Find our target string
5001
- if ( lineContents . indexOf ( tgtString ) > - 1 ) {
5002
+ if ( - 1 < lineContents . indexOf ( tgtString ) ) {
5002
5003
// Get text on the line from our target to the end
5003
5004
remainder = thisCM . getLine ( lineNo ) ;
5004
5005
strPos = remainder . indexOf ( tgtString ) ;
5005
- remainder = remainder . slice ( remainder . indexOf ( tgtString ) + tgtString . length + 1 ) ;
5006
+ remainder = remainder . slice ( remainder . indexOf ( tgtString ) + tgtString . length + 1 ) ;
5006
5007
// Replace the function name if any
5007
- replaceString = replaceString . replace ( / V A R / g, remainder ) ;
5008
+ replaceString = replaceString . replace ( / V A R / g, remainder ) ;
5008
5009
// Get replaced string from start to our strPos
5009
- replacedLine = thisCM . getLine ( lineNo ) . slice ( 0 , strPos ) ;
5010
+ replacedLine = thisCM . getLine ( lineNo ) . slice ( 0 , strPos ) ;
5010
5011
// Trim whitespace from start
5011
5012
whiteSpace = thisCM . getLine ( lineNo ) . length - thisCM . getLine ( lineNo ) . replace ( / ^ \s \s * / , '' ) . length ;
5012
- whiteSpace = thisCM . getLine ( lineNo ) . slice ( 0 , whiteSpace ) ;
5013
+ whiteSpace = thisCM . getLine ( lineNo ) . slice ( 0 , whiteSpace ) ;
5013
5014
// Replace indent with whatever whitespace we have
5014
- replaceString = replaceString . replace ( / I N D E N T / g, whiteSpace ) ;
5015
+ replaceString = replaceString . replace ( / I N D E N T / g, whiteSpace ) ;
5015
5016
replacedLine += replaceString ;
5016
5017
// Get cursor position
5017
5018
curPos = replacedLine . indexOf ( "CURSOR" ) ;
5018
5019
sPos = 0 ;
5019
5020
lineNoCount = lineNo ;
5020
- for ( i = 0 ; i < replacedLine . length ; i ++ ) {
5021
- if ( replacedLine . indexOf ( "\n" , sPos ) < replacedLine . indexOf ( "CURSOR" ) ) {
5022
- sPos = replacedLine . indexOf ( "\n" , sPos ) + 1 ;
5023
- lineNoCount = lineNoCount + 1 ;
5021
+ for ( let i = 0 ; i < replacedLine . length ; i ++ ) {
5022
+ if ( replacedLine . indexOf ( "\n" , sPos ) < replacedLine . indexOf ( "CURSOR" ) ) {
5023
+ sPos = replacedLine . indexOf ( "\n" , sPos ) + 1 ;
5024
+ lineNoCount = lineNoCount + 1 ;
5024
5025
}
5025
5026
}
5026
5027
// Clear the cursor string and set the cursor there
5027
- thisCM . replaceRange ( replacedLine . replace ( "CURSOR" , "" ) , { line :lineNo , ch :0 } , { line :lineNo , ch :1000000 } , "+input" ) ;
5028
- thisCM . setCursor ( lineNoCount , curPos ) ;
5028
+ thisCM . replaceRange ( replacedLine . replace ( "CURSOR" , "" ) , { line : lineNo , ch : 0 } , { line : lineNo , ch : 1000000 } , "+input" ) ;
5029
+ thisCM . setCursor ( lineNoCount , curPos ) ;
5029
5030
// Finally, focus on the editor
5030
- this . focus ( this . editorFocusInstance . indexOf ( 'diff' ) > - 1 ? true : false ) ;
5031
+ this . focus ( - 1 < this . editorFocusInstance . indexOf ( 'diff' ) ? true : false ) ;
5031
5032
}
5032
5033
} ,
5033
5034
0 commit comments