@@ -10,6 +10,7 @@ export default class ExpressionHighlighter extends EventDispatcher {
1010 this . editor = editor ;
1111 this . activeMarks = [ ] ;
1212 this . hoverMarks = [ ] ;
13+ this . widgets = [ ] ;
1314 }
1415
1516 draw ( tokens ) {
@@ -60,13 +61,52 @@ export default class ExpressionHighlighter extends EventDispatcher {
6061 } ) ;
6162 }
6263
64+ drawError ( errors ) {
65+ this . clearError ( ) ;
66+
67+ const pre = ExpressionHighlighter . CSS_PREFIX ;
68+ const editor = this . editor ;
69+ editor . operation ( ( ) => {
70+ for ( const error of errors ) {
71+ const location = Editor . calcRangePos (
72+ this . editor ,
73+ error . location . start ,
74+ error . location . end - error . location . start
75+ ) ;
76+ const widget = document . createElement ( "span" ) ;
77+ widget . className = `${ pre } -error` ;
78+
79+ widget . style . height = `2px` ;
80+ widget . style . zIndex = "10" ;
81+ widget . setAttribute ( "data-tippy-content" , error . message ) ;
82+
83+ editor . addWidget ( location . startPos , widget ) ;
84+ const startCoords = editor . charCoords ( location . startPos , "local" ) ;
85+ const endCoords = editor . charCoords ( location . endPos , "local" ) ;
86+ widget . style . left = `${ startCoords . left + 1 } px` ;
87+ widget . style . top = `${ startCoords . bottom } px` ;
88+ widget . style . width = `${ endCoords . left - startCoords . left - 2 } px` ;
89+
90+ this . widgets . push ( widget ) ;
91+ }
92+ } ) ;
93+ }
94+
6395 clear ( ) {
6496 this . editor . operation ( ( ) => {
65- let marks = this . activeMarks ;
66- for ( var i = 0 , l = marks . length ; i < l ; i ++ ) {
67- marks [ i ] . clear ( ) ;
97+ for ( const mark of this . activeMarks ) {
98+ mark . clear ( ) ;
99+ }
100+ this . activeMarks . length = 0 ;
101+ } ) ;
102+ }
103+
104+ clearError ( ) {
105+ this . editor . operation ( ( ) => {
106+ for ( const widget of this . widgets ) {
107+ widget . parentNode . removeChild ( widget ) ;
68108 }
69- marks . length = 0 ;
109+ this . widgets . length = 0 ;
70110 } ) ;
71111 }
72112
@@ -77,9 +117,7 @@ export default class ExpressionHighlighter extends EventDispatcher {
77117 return ;
78118 }
79119
80- while ( this . hoverMarks . length ) {
81- this . hoverMarks . pop ( ) . clear ( ) ;
82- }
120+ this . clearHover ( ) ;
83121
84122 if ( selection ) {
85123 this . drawBorder ( selection , "selected" ) ;
@@ -119,9 +157,12 @@ export default class ExpressionHighlighter extends EventDispatcher {
119157 }
120158
121159 clearHover ( ) {
122- while ( this . hoverMarks . length ) {
123- this . hoverMarks . pop ( ) . clear ( ) ;
124- }
160+ this . editor . operation ( ( ) => {
161+ for ( const mark of this . hoverMarks ) {
162+ mark . clear ( ) ;
163+ }
164+ this . hoverMarks . length = 0 ;
165+ } ) ;
125166 }
126167}
127168
0 commit comments