@@ -246,30 +246,54 @@ class Editor extends React.Component {
246
246
) ;
247
247
}
248
248
249
- if ( this . props . runtimeErrorWarningVisible ) {
250
- this . props . consoleEvents . forEach ( ( consoleEvent ) => {
251
- if ( consoleEvent . method === 'error' ) {
252
- if (
253
- consoleEvent . data &&
254
- consoleEvent . data [ 0 ] &&
255
- consoleEvent . data [ 0 ] . indexOf &&
256
- consoleEvent . data [ 0 ] . indexOf ( ')' ) > - 1
257
- ) {
258
- const sourceAndLoc = consoleEvent . data [ 0 ]
259
- . split ( '\n' ) [ 1 ]
260
- . split ( '(' ) [ 1 ]
261
- . split ( ')' ) [ 0 ] ;
262
- const [ source , line , column ] = sourceAndLoc . split ( ':' ) ;
263
- const lineNumber = parseInt ( line , 10 ) - 1 ;
264
- this . _cm . addLineClass (
265
- lineNumber ,
266
- 'background' ,
267
- 'line-runtime-error'
268
- ) ;
249
+ if ( this . props . consoleEvents . length !== prevProps . consoleEvents . length ) {
250
+ if ( this . props . runtimeErrorWarningVisible ) {
251
+ // todo here, need to select the right file
252
+
253
+ this . props . consoleEvents . forEach ( ( consoleEvent ) => {
254
+ if ( consoleEvent . method === 'error' ) {
255
+ if ( consoleEvent . data && consoleEvent . data [ 0 ] ) {
256
+ let sourceAndLoc ;
257
+ if (
258
+ consoleEvent . data [ 0 ] . indexOf &&
259
+ consoleEvent . data [ 0 ] . indexOf ( ')' ) > - 1
260
+ ) {
261
+ sourceAndLoc = consoleEvent . data [ 0 ] // eslint-disable-line
262
+ . split ( '\n' ) [ 1 ]
263
+ . split ( '(' ) [ 1 ]
264
+ . split ( ')' ) [ 0 ] ;
265
+ } else {
266
+ sourceAndLoc = consoleEvent . data [ 0 ] // eslint-disable-line
267
+ . split ( '\n' ) [ 1 ]
268
+ . split ( 'at ' ) [ 1 ] ;
269
+ }
270
+ const [ source , line ] = sourceAndLoc . split ( ':' ) ;
271
+
272
+ // get the file that this message is coming from, and then select it
273
+ const sourceArray = source . split ( '/' ) ;
274
+ const fileName = sourceArray . slice ( - 1 ) [ 0 ] ;
275
+ const filePath = sourceArray . slice ( 0 , - 1 ) . join ( '/' ) ;
276
+ const fileWithError = this . props . files . find (
277
+ ( f ) => f . name === fileName && f . filePath === filePath
278
+ ) ;
279
+ this . props . setSelectedFile ( fileWithError . id ) ;
280
+ const lineNumber = parseInt ( line , 10 ) - 1 ;
281
+ this . _cm . addLineClass (
282
+ lineNumber ,
283
+ 'background' ,
284
+ 'line-runtime-error'
285
+ ) ;
286
+ }
269
287
}
288
+ } ) ;
289
+ } else {
290
+ for ( let i = 0 ; i < this . _cm . lineCount ( ) ; i += 1 ) {
291
+ this . _cm . removeLineClass ( i , 'background' , 'line-runtime-error' ) ;
270
292
}
271
- } ) ;
272
- } else {
293
+ }
294
+ }
295
+
296
+ if ( this . props . file . id !== prevProps . file . id ) {
273
297
for ( let i = 0 ; i < this . _cm . lineCount ( ) ; i += 1 ) {
274
298
this . _cm . removeLineClass ( i , 'background' , 'line-runtime-error' ) ;
275
299
}
@@ -467,7 +491,8 @@ Editor.propTypes = {
467
491
hideRuntimeErrorWarning : PropTypes . func . isRequired ,
468
492
runtimeErrorWarningVisible : PropTypes . bool . isRequired ,
469
493
provideController : PropTypes . func . isRequired ,
470
- t : PropTypes . func . isRequired
494
+ t : PropTypes . func . isRequired ,
495
+ setSelectedFile : PropTypes . func . isRequired
471
496
} ;
472
497
473
498
function mapStateToProps ( state ) {
0 commit comments