@@ -68,15 +68,13 @@ function markInterval(cm, interval, className, canHighlightBlocks) {
68
68
if ( canHighlightBlocks && isBlockSelectable ( cm , startPos , endPos ) ) {
69
69
return markBlock ( cm , startPos . line , endPos . line , className ) ;
70
70
}
71
- cm . getWrapperElement ( ) . classList . add ( 'highlighting' ) ;
72
71
return cm . markText ( startPos , endPos , { className : className } ) ;
73
72
}
74
73
75
- function clearMark ( cm , mark ) {
74
+ function clearMark ( mark ) {
76
75
if ( mark ) {
77
76
mark . clear ( ) ;
78
77
}
79
- cm . getWrapperElement ( ) . classList . remove ( 'highlighting' ) ;
80
78
}
81
79
82
80
function indexToHeight ( cm , index ) {
@@ -266,9 +264,11 @@ function createTraceElement(traceNode, parent, input) {
266
264
}
267
265
if ( traceNode . interval ) {
268
266
inputMark = markInterval ( inputEditor , traceNode . interval , 'highlight' , false ) ;
267
+ inputEditor . getWrapperElement ( ) . classList . add ( 'highlighting' ) ;
269
268
}
270
269
if ( traceNode . expr . interval ) {
271
270
grammarMark = markInterval ( grammarEditor , traceNode . expr . interval , 'active-appl' , false ) ;
271
+ grammarEditor . getWrapperElement ( ) . classList . add ( 'highlighting' ) ;
272
272
scrollToInterval ( grammarEditor , traceNode . expr . interval ) ;
273
273
}
274
274
var ruleName = traceNode . expr . ruleName ;
@@ -285,9 +285,11 @@ function createTraceElement(traceNode, parent, input) {
285
285
if ( input ) {
286
286
input . classList . remove ( 'highlight' ) ;
287
287
}
288
- clearMark ( inputEditor , inputMark ) ;
289
- clearMark ( grammarEditor , grammarMark ) ;
290
- clearMark ( grammarEditor , defMark ) ;
288
+ inputMark = clearMark ( inputMark ) ;
289
+ grammarMark = clearMark ( grammarMark ) ;
290
+ defMark = clearMark ( defMark ) ;
291
+ grammarEditor . getWrapperElement ( ) . classList . remove ( 'highlighting' ) ;
292
+ inputEditor . getWrapperElement ( ) . classList . remove ( 'highlighting' ) ;
291
293
} ) ;
292
294
wrapper . _input = input ;
293
295
@@ -358,30 +360,39 @@ function isPrimitive(expr) {
358
360
}
359
361
}
360
362
361
- // Hides or shows the grammar error.
362
363
var errorMarks = {
363
364
grammar : null ,
364
365
input : null
365
366
} ;
366
367
367
368
function hideError ( category , editor ) {
368
- if ( errorMarks [ category ] ) {
369
- clearMark ( editor , errorMarks [ category ] . interval ) ;
370
- errorMarks [ category ] . widget . clear ( ) ;
369
+ var errInfo = errorMarks [ category ] ;
370
+ if ( errInfo ) {
371
+ errInfo . mark . clear ( ) ;
372
+ clearTimeout ( errInfo . timeout ) ;
373
+ if ( errInfo . widget ) {
374
+ errInfo . widget . clear ( ) ;
375
+ }
371
376
errorMarks [ category ] = null ;
372
377
}
373
378
}
374
379
375
- function showError ( category , editor , message , interval ) {
376
- var el = createElement ( '.errorItem' ) ;
377
- el . textContent = message ;
378
- var pos = editor . posFromIndex ( interval . endIdx ) ;
380
+ function setError ( category , editor , interval , message ) {
381
+ hideError ( category , editor ) ;
382
+
379
383
errorMarks [ category ] = {
380
- interval : markInterval ( editor , interval , 'error' , false ) ,
381
- widget : editor . addLineWidget ( pos . line , el )
384
+ mark : markInterval ( editor , interval , 'error-interval' , false ) ,
385
+ timeout : setTimeout ( function ( ) { showError ( category , editor , interval , message ) ; } , 1500 ) ,
386
+ widget : null
382
387
} ;
383
388
}
384
389
390
+ function showError ( category , editor , interval , message ) {
391
+ var errorEl = createElement ( '.error' , message ) ;
392
+ var line = editor . posFromIndex ( interval . endIdx ) . line ;
393
+ errorMarks [ category ] . widget = editor . addLineWidget ( line , errorEl ) ;
394
+ }
395
+
385
396
function useLocalStorage ( ) {
386
397
return typeof localStorage !== 'undefined' &&
387
398
typeof Storage === 'function' &&
@@ -397,6 +408,14 @@ function setEditorValueFromLocalStorage(editor, key) {
397
408
}
398
409
}
399
410
411
+ function hideBottomOverlay ( ) {
412
+ $ ( '#bottomSection .overlay' ) . style . width = 0 ;
413
+ }
414
+
415
+ function showBottomOverlay ( ) {
416
+ $ ( '#bottomSection .overlay' ) . style . width = '100%' ;
417
+ }
418
+
400
419
// Main
401
420
// ----
402
421
@@ -406,6 +425,7 @@ function setEditorValueFromLocalStorage(editor, key) {
406
425
var grammarChanged = true ;
407
426
408
427
function triggerRefresh ( delay ) {
428
+ showBottomOverlay ( ) ;
409
429
if ( refreshTimeout ) {
410
430
clearTimeout ( refreshTimeout ) ;
411
431
}
@@ -418,16 +438,14 @@ function setEditorValueFromLocalStorage(editor, key) {
418
438
setEditorValueFromLocalStorage ( inputEditor , 'input' ) ;
419
439
setEditorValueFromLocalStorage ( grammarEditor , 'grammar' ) ;
420
440
421
- inputEditor . on ( 'change' , function ( ) { triggerRefresh ( 150 ) ; } ) ;
441
+ inputEditor . on ( 'change' , function ( ) { triggerRefresh ( 250 ) ; } ) ;
422
442
grammarEditor . on ( 'change' , function ( ) {
423
443
grammarChanged = true ;
424
- triggerRefresh ( 150 ) ;
444
+ hideError ( 'grammar' , grammarEditor ) ;
445
+ triggerRefresh ( 250 ) ;
425
446
} ) ;
426
447
427
448
function refresh ( ) {
428
- $ ( '#expandedInput' ) . innerHTML = '' ;
429
- $ ( '#parseResults' ) . innerHTML = '' ;
430
-
431
449
hideError ( 'input' , inputEditor ) ;
432
450
if ( useLocalStorage ( ) ) {
433
451
localStorage . setItem ( 'input' , inputEditor . getValue ( ) ) ;
@@ -436,7 +454,6 @@ function setEditorValueFromLocalStorage(editor, key) {
436
454
if ( grammarChanged ) {
437
455
grammarChanged = false ;
438
456
439
- hideError ( 'grammar' , grammarEditor ) ;
440
457
var grammarSrc = grammarEditor . getValue ( ) ;
441
458
if ( useLocalStorage ( ) ) {
442
459
localStorage . setItem ( 'grammar' , grammarSrc ) ;
@@ -447,8 +464,8 @@ function setEditorValueFromLocalStorage(editor, key) {
447
464
console . log ( e ) ; // eslint-disable-line no-console
448
465
449
466
var message = e . shortMessage ? e . shortMessage : e . message ;
450
- showError ( 'grammar' , grammarEditor , message , e . interval ) ;
451
- // If the grammar is unusable, prevent the input to be parsed.
467
+ setError ( 'grammar' , grammarEditor , e . interval , message ) ;
468
+ // If the grammar is unusable, prevent the input from being parsed.
452
469
grammar = null ;
453
470
return ;
454
471
}
@@ -457,13 +474,16 @@ function setEditorValueFromLocalStorage(editor, key) {
457
474
if ( ! grammar ) {
458
475
return ;
459
476
}
477
+ hideBottomOverlay ( ) ;
478
+ $ ( '#expandedInput' ) . innerHTML = '' ;
479
+ $ ( '#parseResults' ) . innerHTML = '' ;
460
480
461
481
var trace = grammar . trace ( inputEditor . getValue ( ) ) ;
462
482
if ( trace . result . failed ( ) ) {
463
483
// Intervals with start == end won't show up in CodeMirror.
464
484
var interval = trace . result . getInterval ( ) ;
465
485
interval . endIdx += 1 ;
466
- showError ( 'input' , inputEditor , 'Expected: ' + trace . result . getExpectedText ( ) , interval ) ;
486
+ setError ( 'input' , inputEditor , interval , 'Expected ' + trace . result . getExpectedText ( ) ) ;
467
487
}
468
488
469
489
// Refresh the option values.
0 commit comments